Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29755

Send mail from office 365 for business in C#

$
0
0

I tried sending mail in my ASP.NET CORE project by C#. I ran code in emulation (IIS Express) but I get an error:

The SMTP server requires a secure connection or the client was not authenticated.

Please can you help me?

My code:

MailMessage msg = new MailMessage();msg.To.Add(new MailAddress("formail@mail.com", "John Doe"));msg.From = new MailAddress("frommail@mail.com", "Jane Doe");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("frommail@mail.com", "Password");client.Port = 587; client.Host = "smtp.office365.com";client.DeliveryMethod = SmtpDeliveryMethod.Network;client.EnableSsl = true;try{    client.Send(msg);    return Content("Message sent successfully");}catch (Exception ex){    return Content(ex.ToString());}

Full error:

System.Net.Mail.SmtpException: 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 [AM3PR07CA0113.eurprd07.prod.outlook.com]

Thank you very much.


Viewing all articles
Browse latest Browse all 29755

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>