I have an application the send e-mail by the users using the outlook smtp server. This application works fine on the localhost, with the same credetions. But when I publish my ASP.NET Core application on the Azure, I receive the following exception:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [SN6PR04CA0015.namprd04.prod.outlook.com]
To send e-mails I am using the code:
MailMessage mail = new MailMessage(
EmailServiceConfiguration.SenderMail(),
addresses.Aggregate((seed, value) => seed += "," + value)
);
SmtpClient client = new SmtpClient();
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "mypassword");
client.Host = "smtp-mail.outlook.com";
mail.Subject = "My subject";
mail.Body = "My text";
mail.IsBodyHtml = true;
client.Send(mail);
Remembering that this exception only happens when the application is running on azure, local host is work and normal.
Thanks.