- Home /
Sending an email from my project crashes the unity editor
when i call this script the unity editor freezes and the program is shown as not responding in the task manager and also it does the same thing in the webGL build when the script is called. I cant get any error messages because it just freezes. I got this code from another help topic that stated it worked. Not sure what i did wrong. (i changed the email and password to a default value in this post for security issues)
public class mono_gmail : MonoBehaviour {//this script will send an email to a gmail address when called
public void Send_Mail()
{ // set Api Compatibility Level to ".NET 2.0" instead of ".NET 2.0 Subset" under player settings
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("email@gmail.com");
mail.To.Add("email@gmail.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("email@gmail.com", "password") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
}
catch(Exception ex) {
Console.WriteLine(ex.Message);
throw ex;
}
Debug.Log("success");
}
}
made a new visual studio project with the same code and got a, System.Net.$$anonymous$$ail.SmtpException when the program timed out. Unable to read data from the transport connection
System.Net.$$anonymous$$ail.SmtpException was unhandled HResult=-2146233088 $$anonymous$$essage=Failure sending mail. Source=WindowsFormsApplication1
InnerException: HResult=-2146232800 $$anonymous$$essage=Unable to read data from the transport connection: net_io_connectionclosed. Source=System StackTrace: at System.Net.$$anonymous$$ail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.$$anonymous$$ail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.$$anonymous$$ail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.$$anonymous$$ail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.$$anonymous$$ail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.$$anonymous$$ail.SmtpClient.GetConnection() at System.Net.$$anonymous$$ail.SmtpClient.Send($$anonymous$$ail$$anonymous$$essage message) InnerException:
i dont know why but removing the line that sets the port (smtpServer.Port = 587;) fixed the problem