I am using following code to send email. The Code works correctly in my local Machine. But on Production server i am getting the error message
var fromAddres
I had the same problem for an application deployed to Microsoft Azure.
SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
First I approved all unknown devices (some ip-addresses originating from Ireland) on the following page (signed in as the gmail user): https://security.google.com/settings/u/1/security/secureaccount
I used the following settings for the client:
var client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("my_user_name@gmail.com", "my_password");
It started working only after I set the following property on the smtp-client:
client.TargetName = "STARTTLS/smtp.gmail.com";