使用 StartTLS 的 SparkPost SMTP 中继突然出现错误 "Authentication failed because the remote party has closed the transport stream."

SparkPost SMTP relay with StartTLS suddenly gives error "Authentication failed because the remote party has closed the transport stream."

我在 ASP.NET 4.0 框架上用 VB 编写了一个(长)运行 网络应用程序。

我们使用 SparkPost 发送电子邮件已经有一段时间了,但是几天后(不确定确切日期),电子邮件功能停止工作并开始显示以下错误消息

Authentication failed because the remote party has closed the transport stream.

我们使用 MailKit 版本 1.22(最新支持 ASP.NET 4.0)来建立连接并发送电子邮件,如下所示:

Using objMessage As New MailMessage(from, to, title, message)
    objMessage.IsBodyHtml = True
        'https://github.com/jstedfast/MailKit
        Using client As New MailKit.Net.Smtp.SmtpClient()
            ''accept all SSL certificates (in case the server supports STARTTLS)
            client.ServerCertificateValidationCallback = Function(sender, certificate, chain, errors)
                                                             Return True
                                                         End Function

            ''Note: since we don't have an OAuth2 token, disable the XOAUTH2 authentication mechanism.
            client.AuthenticationMechanisms.Remove("XOAUTH2")

            client.AuthenticationMechanisms.Add("AUTH LOGIN")

            client.Connect("smtp.sparkpostmail.com", 587, SecureSocketOptions.StartTls)

            ''Note: only needed if the SMTP server requires authentication
            client.Authenticate("SMTP_Injection", "**********************")//the asterixes are the API key

            client.Send(objMessage)
            client.Disconnect(True)
        End Using

    End Using

SparkPost 文档希望我使用此 StartTLS 设置。

我了解到 SparkPost 最近停止支持 TSL 1.0。这会是罪魁祸首吗?

.NET Framework 4.0 使用SSL3.0 或TLS1.0 作为默认协议。解决此问题的最简单方法是将现有应用程序升级到 .NET Framework 4.6.2。升级后,您的应用将默认使用 TLS1.2 协议。您可以阅读更多相关信息 here