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("from_address@gmail.com", my_name);
        var toAddress = new MailAddress("to_address@gmail.com", "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 = "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.CC.Add(lanzi);

        message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure;

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

        smtp.Send(message);

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 http://support.google.com/mail/bin/answer.py?answer=14257 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
Bye!

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.