In May 2022, Google no longer supports the "Allow less secure apps" feature. So , I enabled two step verification in gmail using my phone and generated an App Password (16 digit random string) and used it in my C# code, but getting this excepton
"Failure sending mail. System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed."
The emails are read but unable to send emails, Please assist.
//Send email to client...
SmtpClient objSmtpClient = new SmtpClient();
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.EnableSsl = true;
objSmtpClient.Port = 587;
Email objSendMail = new Email();
objSmtpClient.Host = "smtp.gmail.com";
objSmtpClient.Credentials = new NetworkCredential("example@gmail.com","MyAppPassword");
objSendMail.From = "example@gmail.com";
objSendMail.To = customerEmail;
objSendMail.Subject = "Test subject";
objSendMail.Body = "Test Body";
try
{
var isSendEmail = objSendMail.SendEmail(objSmtpClient);
}
catch (Exception ex)
{
AppLogger.LogError(ex.Message + Environment.NewLine + ex.ToString());
return false;
}