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?

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 :slight_smile:

Gmail accounts require SSL i’m afraid