SMTP Stopped Working

The following Code which was working previously suddenly stopped working. Anyone have any idea what’s causing it or how to fix it ?

using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;

public void sendMail (string targetEmail, string subject, string content){

     MailMessage mail = new MailMessage();

     mail.From = new MailAddress(acEmail);
     mail.To.Add(targetEmail);
     mail.Subject = subject;
     mail.Body = content;

     SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
     smtpServer.Port = 587;
     smtpServer.Credentials = new System.Net.NetworkCredential(acEmail, acPW) as ICredentialsByHost;
     smtpServer.EnableSsl = true;
     ServicePointManager.ServerCertificateValidationCallback =
       delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
     { return true; };
     smtpServer.Send(mail);
     Debug.Log("Email Sent");
}

The Error Message shows the following :

2 Likes

https://www.google.com/settings/security/lesssecureapps
Check enable and try again

4 Likes

hey thanks this much help me :smile:

Thanks for this!