0

I'm trying to send email from my ASP.NET core 2.2 web application, using my company Office 365 email account (we have Office 365 Business Basic package).

I found this code on StackOverflow:

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("someone@somedomain.com", "SomeOne"));
msg.From = new MailAddress("you@yourdomain.com", "You");
msg.Subject = "This is a Test Mail";
msg.Body = "This is a test message using Exchange OnLine";
msg.IsBodyHtml = true;

SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("your user name", "your password");
client.Port = 587; // You can use Port 25 if 587 is blocked (mine is!)
client.Host = "smtp.office365.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
try
{
    client.Send(msg);
    lblText.Text = "Message Sent Succesfully";
}
catch (Exception ex)
{
    lblText.Text = ex.ToString();
}

However I got this error:

    The SMTP server requires a secure connection or the client was not authenticated. 
    The server response was: 5.7.57 Client not authenticated to send mail. 
    Error: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. 
    Visit https://aka.ms/smtp_auth_disabled for more information. [HK2PR03CA0048.apcprd03.prod.outlook.com]

And on the link on the error above they stated: I followed the link and enabled the Authenticated SMTP, like the pic below: enter image description here However, then I got this error:

The SMTP server requires a secure connection or the client was not authenticated. 
The server response was: 5.7.57 Client not authenticated to send mail. [HK2PR02CA0162.apcprd02.prod.outlook.com]

Then i searched for that error but couldn't find any information.

Now I have no clues to continue, please help me to fix this, thank you so much.

Liberty
  • 345
  • 1
  • 4
  • 10
  • Does this answer your question? [5.7.57 SMTP - Client was not authenticated to send anonymous mail during MAIL FROM error](https://stackoverflow.com/questions/30342884/5-7-57-smtp-client-was-not-authenticated-to-send-anonymous-mail-during-mail-fr) – Eugene Astafiev Jul 05 '21 at 15:18
  • @EugeneAstafiev no it didn't help :(( there's nothing related to anonymous mail – Liberty Jul 09 '21 at 05:17

0 Answers0