Can't access to gmail using the build

Hi everyone.
I need to send an email using the game and I’ve this issue.

When I try the game in the editor it sends the mail correctly.

When I build the game and I try to send the email using the .exe file it raises this:


Platform assembly: D:\DropBox Storage\Dropbox\Project\Exec\Exec PC\Updated version\OSR_Data\Managed\Mono.Security.dll (this message is harmless)
SmtpException: 530-5.5.1 Authentication Required. Learn more at

530 5.5.1 Check Gmail through other email platforms - Gmail Help l10sm4506847wif.20 - gsmtp

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

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

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


The Code I’m using is the following:

static public void mono_gmail (string receiver, string subject, string body)
	{
		MailMessage mail = new MailMessage();

		//mail content here
		mail.From = new MailAddress(sampleemail@gmail.com, "Name");
		mail.To.Add(receiver);
		mail.Subject = subject;
		mail.Body = body;

        //attaching a file here
		System.Net.Mail.Attachment data;
	    data = new System.Net.Mail.Attachment("filePathhere");
		mail.Attachments.Add(data);

		SmtpClient smtpServer = new SmtpClient(senderSmtp);
		smtpServer.Port = 587;

		smtpServer.Credentials = new System.Net.NetworkCredential(senderEmail, senderPassword) as ICredentialsByHost;
   		smtpServer.EnableSsl = true;
		ServicePointManager.ServerCertificateValidationCallback = 
		delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
		{ return true; };
		
		smtpServer.Send(mail);
		Debug.Log("success");
		
	}

I just need to change Api Compatibility Level from “.NET 2.0 Subset” to “.NET 2.0”.

You can find it in player settings (File->Build Settings…->Player Settings…->OtherSettings)

Found the solutions in these answers:

Lovely and sweet

Ensure that you have changed Internet access from auto to require in Player settings --> other settings --> configuration

Use this reference to create application specified password.