My code for sending email through Gmail’s smtp:
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("my_user_name", "my_password");
MailMessage message =
new MailMessage(new MailAddress("from...@gmail.com"), new MailAddress("to...@gmail.com"));
message.Body = "body";
message.Subject = "subject";
client.Send(message);
The code works on my local machine and when I publish at Azure as “Web Site”.
BUT when I publish in a “Cloud Service” I get this exception:
System.Net.Mail.SmtpException: The SMTP server requires a secure connection
or the client was not authenticated. The server response was:
5.5.1 Authentication Required. Learn more at
Is there anything that differ a Windows Azure “Web site” from a “Cloud Service” that could have this effect?
Thanks!
Use following SMTP settings in Web.config:
I think you are passing wrong credentials. Use @gmail.com suffix in your user name and try to set bodyhtml property true also…
Hope this will work for you.. It always work correctly to me..
Check answer’s comment in the this SO thread.