Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmail: Unable to read data from the transport connection: net_io_connectionclosed

Tags:

c#

email

gmail

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?!?!

like image 339
DonJoe Avatar asked Sep 12 '16 16:09

DonJoe


People also ask

What is Net_io_connectionclosed?

Unable to read data from the transport connection: net_io_connectionclosed". This can happen if there are issues connecting to the SMTP server.

How do I fix my SMTP server for Gmail?

In Google mail, you must allow "less secure" apps access in order for your SMTP settings to work. There are two places this setting must be enabled: Visit: https://myaccount.google.com/ and on the left side, go to Security, then scroll down to Less secure app access: Turn this on, as you must allow it to use SMTP.

What is SMTP server error for Gmail?

SMTP is an internet standard used by mail servers to send and receive email. SMTP error messages help you understand why a message wasn't sent successfully. If incoming or outgoing messages are bouncing, check the bounce messages for an SMTP error code that can help you diagnose the problem.


2 Answers

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

like image 153
slasky Avatar answered Nov 15 '22 16:11

slasky


SmtpException: Unable to read data from the transport connection: net_io_connectionclosed

There are two solutions. First solution is for app level (deployment required) and second one is for machine level (especially if you use an out-of-the-box / off-the-shelf app)

When we checked the exception, we saw that the protocol is "ssl|tls" depriciated pair.

Since we don't want to deploy, we prefer machine level change (Solution 2).

On August 18, Microsoft announced that they will disable Transport Layer Security (TLS) 1.0 and 1.1 connections to Exchange Online “in 2022.” https://office365itpros.com/2021/08/19/exchange-online-to-introduce-legacy-smtp-endpoint-in-2022/

Firstly let's check the network (Anything prevents your email sent request? firewall, IDS, etc.)

By using PowerShell check Transport Layer Security protocols

[Net.ServicePointManager]::SecurityProtocol

My Output: Tls, Tls11, Tls12

Test SMTP Authentication over TLS

$HostName = [System.Net.DNS]::GetHostByName($Null).HostName
$Message = new-object Net.Mail.MailMessage 
$smtp = new-object Net.Mail.SmtpClient("smtp.gmail.com", 587) 
$smtp.Credentials = New-Object System.Net.NetworkCredential("me***@gmail.com", "PassMeme"); 
$smtp.EnableSsl = $true 
$smtp.Timeout = 400000  
$Message.From = "[email protected]" 
$Message.Subject = $HostName + " PowerShell Gmail Test"
$Message.Body = "Email Body Message"
$Message.To.Add("[email protected]") 
#$Message.Attachments.Add("C:\foo\attach.txt") 
$smtp.Send($Message)

My output: There is no error message If there is any message on your output window something prevents your email sent request.

If everything is ok there should be two solutions.

Solution 1:

Application Level TLS 1.2 Configuration (Optional) Application deployment required.

Explicitly choose TLS in C# or VB code:

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

Solution 2:

Machine level TLS 1.2 .NET Framework configuration Application deployment NOT required.

Set the SchUseStrongCrypto registry setting to DWORD:00000001. You should restart the server.

For 32-bit applications on 32-bit systems or 64-bit applications on 64-bit systems), update the following subkey value:

HKEY_LOCAL_MACHINE\SOFTWARE\
   \Microsoft\.NETFramework\\<version>
      SchUseStrongCrypto = (DWORD): 00000001

For 32-bit applications that are running on x64-based systems, update the following subkey value:

HKEY_LOCAL_MACHINE\SOFTWARE\
    Wow6432Node\Microsoft\\.NETFramework\\<version>
       SchUseStrongCrypto = (DWORD): 00000001

For details "How to enable TLS 1.2 on clients" on https://docs.microsoft.com/en-us/mem/configmgr/core/plan-design/security/enable-tls-1-2-client

like image 37
Mehmet TAŞ Avatar answered Nov 15 '22 14:11

Mehmet TAŞ