We used to send emails with the Less secure apps option, which is no longer possible. I have setup the 2 way authentication, I have created an app password, but when I try to send an email with the app password instead of the account password I get the error :
System.Net.Mail.SmtpException: Failure sending mail.
---> System.IO.IOException: Unable to read data from the transport connection: The connection was closed.
The code for sending is :
Smtp = new SmtpClient();
Smtp.UseDefaultCredentials = false;
var NetworkCredentials = new NetworkCredential() { UserName = "...@gmail.com", Password = "..." };
Smtp.Port = 587;
Smtp.EnableSsl = true;
Smtp.Host = "smtp.gmail.com";
Smtp.Credentials = NetworkCredentials;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("...@gmail.com");
msg.To.Add("...@gmail.com");
msg.Subject = "test";
Smtp.Send(msg);