Anup
Anup

Reputation: 9746

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?

Upvotes: 2

Views: 5793

Answers (1)

Joest
Joest

Reputation: 168

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)

Upvotes: 3

Related Questions