- Home /
Error sending Email form the game, using SMTPClient Class
Works just fine in editor and standalone. I think also on android, but fails on IOS
This is the code MailMessage mail = new MailMessage(); mail.From = new MailAddress("me@gmail.com"); mail.To.Add(someone@gmail.com); mail.Subject = "subject"; mail.Body = "body";
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
SmtpServer.Port = 587;
SmtpServer.Credentials = new NetworkCredential("me@gmail.com", "mypass") as ICredentialsByHost;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Timeout = 20000;
SmtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
I've tried to remove the validation callback, made sure my player settings API compatibility is set to .Net 2.0
still no luck/ any help please?
Answer by $$anonymous$$ · May 19, 2014 at 12:15 PM
Using the SMTPClient class, I was able to send an email from unity using the following code:
using System.Net;
using System.Net.Mail;
using UnityEngine;
public class SendMail : MonoBehaviour {
public string sender = "me@mymailaccount.com";
public string receiver = "me@mymailaccount.com";
public string smtpPassword = "mysmtppassword";
public string smtpHost = "mail.mymailacount.com";
// Use this for initialization
private void Start() {
using (var mail = new MailMessage {
From = new MailAddress(sender),
Subject = "test subject",
Body = "Hello there!"
}) {
mail.To.Add(receiver);
var smtpServer = new SmtpClient(smtpHost) {
Port = 25,
Credentials = (ICredentialsByHost)new NetworkCredential(sender, smtpPassword)
};
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
smtpServer.Send(mail);
}
}
}
The difference here is that I dissabled the SSL authentication bacause i simply didnt need it. My script here isnt as different to yours. Try to disable your SSL authentication and see what happens. Hope this helps :)
Answer by maneatingsheep · May 19, 2014 at 12:40 PM
Gmail accounts require SSL i'm afraid
Yep. Got this error (in editor): System.Net.$$anonymous$$ail.SmtpException: 530 5.7.0 $$anonymous$$ust issue a STARTTLS command first.
I'm working in C#, but i don't think it's relevant
Your answer
Follow this Question
Related Questions
Open file with email into iOS app 2 Answers
Send email works in Editor, not on tablet 2 Answers
Send HTML email from iOS app 1 Answer
@ makes problem in ios 1 Answer
Open email popup on iOS 0 Answers