Within our organization we're developing a web app (.NET Core 2.0) which is hosted in an Azure App Service. For our emailing infrastructure, we've installed the latest version of MailKit (version 2.11.1 at the time of writing).
Locally, the process of sending emails works properly and no problems occur, however, after deploying the app to our Azure environment an SslHandshakeException is thrown upon connecting.
MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.
This usually means that the SSL certificate presented by the server is not trusted by the system for one or more of
the following reasons:
1. The server is using a self-signed certificate which cannot be verified.
2. The local system is missing a Root or Intermediate certificate needed to verify the server's certificate.
3. A Certificate Authority CRL server for one or more of the certificates in the chain is temporarily unavailable.
4. The certificate presented by the server is expired or invalid.
5. The set of SSL/TLS protocols supported by the client and server do not match.
See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#SslHandshakeException for possible solutions.
---> System.NotSupportedException: The requested security protocol is not supported.
We're using the following configuration (simplified):
using (var client = new SmtpClient())
{
client.Connect("smtp.office365.com", 587, SecureSocketOptions.StartTls);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate("username", "password");
client.Send(mimeMessage);
}
We've tried playing around with different configuration values (e.g. other ports) but without success.
What did seem to work, though, is downgrading the MailKit package to version 2.3.1.6. Without any configurational changes, the connection did succeed and we were able to send emails.
Could someone explain why the versions behave differently and what steps we possibly need to take to make our configuration work with the newest version of MailKit?
Thanks in advance!