Reputation: 365
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?!?!
Upvotes: 8
Views: 26381
Reputation: 11
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://learn.microsoft.com/en-us/mem/configmgr/core/plan-design/security/enable-tls-1-2-client
Upvotes: 1
Reputation: 3076
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
https://support.google.com/accounts/answer/6010255?hl=en
Upvotes: 10