SendGrid 无法从传输连接读取数据:net_io_connectionclosed

SendGrid Unable to read data from the transport connection: net_io_connectionclosed

自从最近将项目升级到 .net 4.5.2 后,我通过 SendGrid 发送电子邮件时遇到异常抛出

Failure sending mail. System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at System.Net.Mail.SmtpClient.Send(MailMessage message) at SendGridMail.Transport.SMTP.SmtpWrapper.Send(MailMessage mime) at SendGridMail.Transport.SMTP.Deliver(ISendGrid message) at ReACT.Classes.Business.Helpers.Email.Send(String[] to, String[] toNames, Boolean ccToSender, String[] ccTo, String[] ccToNames, String subject, String body, Boolean isHtml, String SMTPServer, String EmailUserName, String EmailPassword, String EmailPort, String SystemEmailAddress, String SystemEmailName, String& FriendlyException, String& TechnicalException)

使用SendGrid服务通过SMTP发送邮件的代码如下-

            SendGridMail.SendGrid vEmailMessage = SendGridMail.SendGrid.GetInstance(vMailMessage.From, vMailMessage.To.ToArray(), vMailMessage.CC.ToArray(), new MailAddress[0], vMailMessage.Subject, vMailMessage.Body, vMailMessage.Body);

            NetworkCredential vCredentials = new NetworkCredential(this.ApplicationSettings.EmailUserName, this.ApplicationSettings.EmailPassword);
            var vTransport = SMTP.GetInstance(vCredentials);

            //Send email message
            vTransport.Deliver(vEmailMessage);

凭据正确并确认工作正常。这个问题自 .net 框架升级后才开始出现,不幸的是,我们无法降级回目标 .net 4

对于那些在通过 SendGrid 发送电子邮件时遇到相同异常的人来说,原来是一项新功能将错误的密码传递给 SendGrid API,导致 AuthenticationFailedException: 535 Authentication failed: Bad username / password

我在下载 Wireshark 后发现了这一点,发现并检查 SendGrid 数据包发现发送到 API 的数据在特定条件下是不正确的。 SendGrid API 然后返回了一个相当有用的 AuthenticationFailedException 异常,但是当这个异常在代码中的 try catch 块中被捕获时,实际的异常被屏蔽并像前面提到的 net_io_connectionclosed IOException

我修复了新应用程序中的错误,问题消失了。如果只有 SendGrid API 抛出的实际异常是在 try catch 块中捕获的异常!

我确实注意到一项服务正在发送大量消息并使用 Azure 免费帐户普通版中可用的所有 25.000/月消息。 为了解决这个问题,我创建了一个新帐户并修复了发送较少数量消息的服务。

我遇到了同样的错误,但这是因为我在 NetworkCredential 中包含了域参数

我遇到了同样的问题。我有错误的用户名。我以为这是我为此创建的 ApiKey,我什至尝试了带域和不带域的电子邮件。解决方案是 SMTP 用户名是 "apikey",就像在那个确切的字符串中一样,不是您的 apikey,不是内部标识符,也不是您给它的 'friendly' 名称。 "apikey".

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

我已遵循此指南 Link: https://sendgrid.com/docs/API_Reference/SMTP_API/integrating_with_the_smtp_api.html

我遇到了同样的问题,但这与在将我的 SMTP 和 API V3 代码升级为基于密钥的身份验证之前在我的 sendgrid 帐户中启用 2FA 有关。

如果您在执行其他操作之前启用 2FA,则会破坏身份验证。

对我们来说 - 这个非描述性错误是由于达到了我们的 sendgrid 电子邮件 api 订阅的发送限制。我建议先检查您的 sendgrid 帐户,然后再搞乱网站设置。

在我们的案例中,这是一个网络问题。我们必须启用公司的防火墙以允许从我们的服务到 SendGrid/Twilio 的 Web 套接字连接,因为我们必须切换到的新 C# 客户端 (SendGridClient) 使用套接字。以前我们使用 C# 通用 MailClient,它使用 SMTP/HTTP.