Office 365 SMTP starts firing net_io_connectionclosed

15,073

Solution 1

This same issue started at my company on February 8th. The problem would come and go with no pattern.

What I believe solved the problem was a change to the SMTP server address.

Our original SMTP server address was podxxxxx.outlook.com and still works most of the time. I checked for the current O365 SMTP server address in our portal and it should be smtp.office365.com.

I changed my config to point to this new address and the problem seems to have gone away. My logs show no errors for the last 24+ hours after the change.

If the error starts happening again I will update this.

Solution 2

In our case, we were already using smtp.office365.com endpoint, yet all of a sudden we started receiving net_io_connectionclosed on one of our machines, while same code was working perfectly on others. Investigation shown that those machines resolved smtp.office365.com to different IP addresses, and it looked like one of the servers was misbehaving.

On attemt to write support inquiry, it appeared that Microsoft is playing bad trick on us:

Recently, we started rejecting a percentage of connections to smtp.office365.com that uses TLS1.0/1.1 for SMTP AUTH (complete disablement will start early 2022).

And that was just it. Switching to TLS 1.2 fixed whole thing.

Solution 3

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

this worked for me

Share:
15,073
Rob
Author by

Rob

Information Security and Software Engineering professional.

Updated on August 03, 2022

Comments

  • Rob
    Rob over 1 year

    A while ago I've configured my ASP.NET C# project to send e-mail via Office 365, but last week it's starting to throw a lot of exceptions.

    System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. 
    at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) 
    at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) 
    at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) 
    at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) 
    at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) 
    at System.Net.Mail.SmtpClient.Send(MailMessage message)
    

    How can I prevent this from happening?

      MailMessage message = new MailMessage(System.Configuration.ConfigurationManager.AppSettings["smtpfrom"], email, strOnderwerp, strBody);
                message.Priority = MailPriority.Normal;
                message.IsBodyHtml = true;
                SmtpClient client = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["smtpserver"], Convert.ToInt32((System.Configuration.ConfigurationManager.AppSettings["smtpport"])));
    
                client.EnableSsl = Boolean.Parse(System.Configuration.ConfigurationManager.AppSettings["smtpssl"]); ;
                client.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["smtpuser"], System.Configuration.ConfigurationManager.AppSettings["smtppass"]);
    
                client.Send(message);
                client.Dispose();
    

    The exceptions seems to be thrown on the Dispose.

  • Rob
    Rob about 9 years
    Replaced pod51014.outlook.com by smtp.office365.com - hoping for the best.
  • Can Sahin
    Can Sahin about 2 years
    It's called a "speedbump", and, apparently, Microsoft does return a useful error message: 421 4.7.66 TLS 1.0 and 1.1 are not supported. Please upgrade/update your client to support TLS 1.2. Visit https://aka.ms/smtp_auth_tls. It's just that the (old) .NET SmtpClient class throws away this information and shows the (useless) generic net_io_connectionclosed message instead.
  • j3ffb
    j3ffb about 2 years
    Yes I had to update the SMTP address to smtp-legacy.office365.com and enable legacy TLS clients in the Exchange Admin Center -> Settings -> Mail flow 'Turn on use of legacy TLS clients.' Opt in to the Exchange Online endpoint for legacy TLS clients using SMTP AUTH
  • Admin
    Admin about 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.