C# – Gmail: Unable to read data from the transport connection: net_io_connectionclosed

cemailgmail

I have an application that has been running upwards of 5 years without any issues. This morning I am no longer able to send emails using a specific Gmail account. The exception that I receive is: Unable to read data from the transport connection: net_io_connectionclosed. Using credentials for another account work fine. The account credentials have not changed and I am able to send emails from the account using the Gmail interface. I have contacted Google and their response was that the account looks ok, it must be your application… my response, the application has not changed and using other credentials work. My relevant code is below, any ideas?

try
            {
                SmtpClient smtpClient = new SmtpClient();
                using (MailMessage message = new MailMessage())
                {
                    message.From = new MailAddress(Program.EMAIL_SENDER_ADDRESS, "SENDER NAME");
                    message.To.Add(new MailAddress(Program.ERROR_RECIPIENT));

                    message.Subject = callingClass + " ERROR: " + subject;

                    message.IsBodyHtml = true;

                    message.Body = body;

                    smtpClient.Host = "smtp.gmail.com";
                    smtpClient.Port = 587;
                    smtpClient.EnableSsl = true;
                    smtpClient.Credentials = new System.Net.NetworkCredential(Program.EMAIL_SENDER_ADDRESS, Program.EMAIL_SENDER_PASSWORD);

                    smtpClient.Send(message);
                    smtpClient.ServicePoint.CloseConnectionGroup(smtpClient.ServicePoint.ConnectionName);
                }
            }
            catch (Exception x)
            {
                //handle exception
            }

UPDATE – About 30 minutes after calling Google, it magically started working again. I guess the app fixed itself?!?!

Best Answer

I had a similar problem with Gmail a while ago. This ended up being the solution as Google had increased their email app security (working as of Sept 2016):

Using this Google MyAccount Page

  1. From your Gmail page, click the avatar image for your account in the upper right corner.
  2. Press 'My Account.'
  3. Press 'Sign In & Security.'
  4. Scroll down to 'Connected Apps & Sites' section.
  5. Toggle 'Allow Less Secure Apps' to On.

https://support.google.com/accounts/answer/6010255?hl=en