asp.netvb.netemailmailkitsparkpost

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


I have a (long) running webapplication written in VB on the ASP.NET 4.0 framework.

We have been using SparkPost to send e-mails for a while, but since a few days (not sure about the exact date), the e-mail functionality has stopped working and started giving the following error message

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

We use MailKit version 1.22 (latest to support ASP.NET 4.0) to make the connection and send the e-mails like so:

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

this setup with StartTLS is what SparkPost documentation wants me to use.

I read that SparkPost has recently stopped supporting TSL 1.0. Could this be the culprit?


Solution

  • The .NET Framework 4.0 use SSL3.0 or TLS1.0 as default protocol. The easiest way to fix the problem is to upgrade your existing application to .NET Framework 4.6.2. After the upgrade your app will use the TLS1.2 protocol as default. You can read more about it here