1

i'm trying to send mail from my asp.net app, on azure, but without success.

Im my local machine im able to do this, with the same code:

MailMessage msg = new MailMessage();
msg.From = new MailAddress("maymail@gmail.com", "myName");
msg.Subject = subject;
msg.Body = body;
msg.BodyEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
msg.IsBodyHtml = html;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 25; //587 works too
client.Credentials = new NetworkCredential("mymail@gmail.com", "myPass");
client.EnableSsl = true;
client.Send(msg);

Im my environment, it works well.

After deploy in azure environment, i receive the exception:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

Anybody knows why?

Thanks a lot!

DenMath
  • 25
  • 1
  • 6

2 Answers2

2

The Azure environment would not have ports available to connect to and interact with SMTP directly, unlike your client environment. There are services available, such as SendGrid which provide an API to send email from within Azure. I highly recommend having a look and using that service instead of your existing approach.

http://sendgrid.com/windowsazure.html

You are able to send email from both your development and azure using a service like SendGrid as well.

Pepto
  • 1,434
  • 10
  • 13
0

Try adding these two lines:

client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;

I would also try port 587 instead of 25.

Noel
  • 3,288
  • 1
  • 23
  • 42