SendGrid Unable to read data from the transport connection: net_io_connectionclosed

For those experiencing the same exception when sending emails via SendGrid, it turned out that a new piece of functionality was passing an incorrect password to the SendGrid API resulting in a AuthenticationFailedException: 535 Authentication failed: Bad username / password.

I discovered this after downloading Wireshark, finding & inspecting the SendGrid packets to find the data sent to the API was incorrect under a certain condition. The SendGrid API then returned a rather helpful AuthenticationFailedException exception however when this exception was caught in a try catch block in code, the actual exception was masked and came out as the aforementioned net_io_connectionclosed IOException

I fixed the bug in our new application and the issue went away. If only the actual exception being thrown by the SendGrid API was the one caught in the try catch block!


I had the same problem. I had the wrong username. I thought this was the ApiKey that I created for this, I even tried the email with and without domain. The solution was that the SMTP username is "apikey", as in that exact string, not your apikey, not the internal identifier nor the 'friendly' name you gave it. Just the exact 6 letters of "apikey".


const string username="apikey";
string pass = "xxxxxxxxxxxxxxxxxxxxx" // login sendgrid.com => create ApiKey
NetworkCredential vCredentials = new NetworkCredential("apikey", pass);

I have followed this guide Link: https://sendgrid.com/docs/API_Reference/SMTP_API/integrating_with_the_smtp_api.html