Send an email from the game

Hi all, I need to send an email from inside the game.

I’ve added the following script, and it works perfectly in the Unity3d editor.

Unluckily it doesn’t work in the runnable deployed .exe file, when I compile the game.

This is my script:

      var fromAddress = new MailAddress("", my_name);
        var toAddress = new MailAddress("", "Johnny");

        const string fromPassword = "my_gmailpassword";
        const string subject = "my_object";

        ServicePointManager.ServerCertificateValidationCallback =
        delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        { return true; };

        var smtp = new SmtpClient
                       Host = "",
                       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;

        message.Attachments.Add(new Attachment(_FileLocation + "\\" + _FileName));


and this is the error I get when running it in windows executable file .exe:

SmtpException: 530-5.5.1 Authentication Required. Learn more at

530 5.5.1 gz3sm12338639wib.2

  at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message) [0x00000] in <filename unknown>:0 

  at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message) [0x00000] in <filename unknown>:0 

  at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x00000] in <filename unknown>:0 

Have u got any ideas how to fix it?

Thanks a lot

Did you make sure that under player settings Api Compatibility Level is set to “.NET 2.0” and not “.NET 2.0 Subset”?

Excelente, me funciono a la perfeccion tenia 2 dias con ese problema.