SmtpClient gmail An existing connection was forcibly closed by the remote host.
I am getting this error when I am trying to send and email
mail.From = new MailAddress("myemail@gmail.com");
mail.To.Add("sendto@gmail.com");
mail.Subject = "Test Mail Subject";
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("myemail@gmail.com", "mypassword") 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 tried different soltuions, disable anti virus firewall, enabling less secure login setting in gmail, but nothing seem to work, Any idea what might be causing this
Answer by Shivarana · Jun 12, 2017 at 03:43 PM
Hi there,
Got exactly the same problem. I tried changing port to 465 which crashes Unity completely. Found other syntax for
SmtpClient smtpServer = new SmtpClient ("smtp.gmail.com", 587);
But result is the same.
Does anyone else has an idea?
Answer by judy3turn · Oct 04, 2017 at 01:21 AM
Having the same issue and it's associated with gmail's increases security. The last suggestion was to try 2 step security but when I tried that the web site put me in an infinite login loop. Sooooo....
Tried with my GoDaddy account and that doesn't work with ssl enabled and their ssl port.
Not a happy camper at the moment
Your answer
![](https://koobas.hobune.stream/wayback/20220612122800im_/https://answers.unity.com/themes/thub/images/avi.jpg)