简体   繁体   中英

C# Mail Sending Error in smtp.office365.com SMTP Server

I am using below Code for SMTP Configuration.

SmtpClient smtp = new SmtpClient
{
    Host = data.SMTPServer, // smtp server address here...
    Port = data.PortNo,
    EnableSsl = data.SSL,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
    Timeout = 30000,
};
smtp.Send(message);

One client has configured SMTP Server - smtp.office365.com.

SMTP Server throws back below Error - Without SSL:-

Error in processing. The server response was: 5.7.3 STARTTLS is required to send mail [XXX.XXX.PROD.OUTLOOK.COM]

With SSL:-

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. [XXXX.XXXX.PROD.OUTLOOK.COM]

Above SMTP Code works perfectly for rest of Clients. Any inputs what needs to be done to fix this?

Make sure that the points below are correct:

  • credentials are correct
  • use the right port number (587 or 25)
  • application must be able to use TLS 1.2 or higher ( you can test this by adding the following code before calling the service: System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM