I have an winform application running on our production floor and it sends email for reporting, so since yesterday its unable to send emails and i got this message
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required."
I checked this post The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required?
and I found that google is not longer supporting 3rd party app, it doesn't allow less secure apps this is from google less secure app Less secure app access:
Some apps and devices use less secure sign-in technology, which makes your account vulnerable. You can turn off access for these apps, which we recommend, or turn it on if you want to use them despite the risks. Google will automatically turn this setting OFF if it’s not being used. This setting is no longer available. Learn more
so I have tried adding SmtpServer.UseDefaultCredentials = false; but nothing works, I think the issue is google that is not longer supporting 3rd party access to email. This is my code
try
{
MailMessage mail = new MailMessage();
System.Net.Mail.SmtpClient SmtpServer =
new System.Net.Mail.SmtpClient("smtp.gmail.com");
string sender = "user@gmail.com";
mail.From = new MailAddress(sender);
mail.To.Add("receiver@plastikon.com");
mail.Priority = MailPriority.High;
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = ($"{body} \n Name of computer: { HostName} ");
SmtpServer.Port = 587;
SmtpServer.Credentials = new
System.Net.NetworkCredential("user@gmail.com", "Password");
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Send(mail);
}
The question is: is there a solution for this or does anyone can recommend me another way to send emails or an API or something?