Intermittent "Unable to read data from the transport connection: net_io_connectionclosed" errors

John Avis by | May 6, 2020 | Web Development

If you are having intermittent problems sending email in .NET using System.Net.Mail consider switching libraries.


I have been facing a problem with an ASP.NET application that sends email using a remote mail server.

Some emails failed to send, and the error message logged was "Unable to read data from the transport connection: net_io_connectionclosed".

The problems were very intermittent and started occurring after a change of mail server. It was not easy to reproduce the problem.

I didn't get much help from the people supporting the new mail server, although they did confirm that the error was also logged at their end.

I also spent plenty of time searching for possible causes and trying various solutions none of which worked.

Sending was done using System.Net.Mail library and there was some suggestion in my research that this has some issues and is actually deprecated (there is some confusion over that though). Microsoft is recommending using an open-source library called MailKit instead.

So I decided to do some experimentation and rather than add any new dependencies I temporarily changed some of my code to use the outdated but believed to be more reliable System.Web.Mail library. The problem went away – no more errors!

Unfortunately System.Web.Mail couldn't easily do one thing I need to do (embedded images that don't also appear as attachments), so I opted to rewrite most of my mail sending code to use MailKit. MailKit can do all that System.Net.Mail and System.Web.Mail can do and more, and it's not hard to switch over to it.

There's been no further email errors with MailKit so I would suggest that you move away from System.Net.Mail if you ever face this error message.

Related Posts

500 Internal Server Error after migrating from IIS 7.5 to IIS 10

by John Avis | November 4, 2019

As support ends for Microsoft Windows Server 2008 I have recently gone through migrating some websites to a new server running Windows Server 2016 and IIS 10 but some of the websites did not work.


tagInput: A simple jQuery plugin for tag entry using Bootstrap 4

by John Avis | October 15, 2019

For a website project I needed a way to enter multiple tags. I just wanted something simple that I could easily modify to suit my own needs, so I wrote my own.


ASP.NET bug with RadioButton GroupName in Repeater

by John Avis | September 1, 2019

I rediscovered a bug in ASP.NET that affects RadioButtons inside repeaters. Here is my solution to the problem.

Comments

There are no comments yet. Be the first to leave a comment!

Leave a Comment

Tags

About

...random postings about web development and programming, Internet, computers and electronics topics.

I recommend ASPnix for web hosting and Crazy Domains for domain registration.

Subscribe

Get the latest posts delivered to your inbox.