- Home /
Sending email with Smtp client not working on Android
Hey Guys,
Here's the code that I use to send an email from my game. public void SendMail() { var fromAddress = new MailAddress("test@email.com", "Test"); var toAddress = new MailAddress("test@email.com", "Test");
const string fromPassword = "thePassword";
const string subject = "this is the subject";
const string body = "this is the body of the message";
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword) as ICredentialsByHost
};
var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
};
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure;
smtp.Send(message);
Debug.Log("Message sent");
}
The code works great in the editor but when I try it on my Android device, I get a SocketException: Unknown host. Does anybody has an idea on how to fix it ?
Thanks a lot for your time,
Claude
Comment