I am trying to send out an email from my windows form application. I have seen a lot of similar posts, but none seem to work. But when I change my settings in gmail to allow less secure apps, the code works. But I don't want to make my account vulnerable for this application. Here's the code and error I get if I don't allow less secure apps.
MailMessage mail = new MailMessage("abc@gmail.com", "xyz@gmail.com", "Test Automation", "Did you receive this?");
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.Credentials = new NetworkCredential("abc@gmail.com", "password");
client.EnableSsl = true;
client.Send(mail);
MessageBox.Show("Mail Sent", "success");
An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Please help!
P.S. : I created an outlook account using my gmail and when i put in the oulook server and credentials, the code works. So is it the issue with new gmail security changes? Other similar questions have their problem solved, but I keep having the same errors after trying pretty much every solution.