-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can not send emails after updating from .NET Core 3.1 to .NET 5 #1140
Comments
MailKit just uses the System.Net.Security.SslStream class without any overrides (other than allowing you to specify the allowed SSL/TLS protocol versions). By default, though, TLS v1.2 is allowed. As far as the crypto algorithms allowed and changing the values in openssl.cnf, I'm not at all experienced with that so I doubt I'd be of much help. Interestingly, when I use openssl to connect to smtp.gmail.com, it uses the algorithm you want:
Is it possible that the openssl.cnf file expects the format of the algorithm name to be |
Thank you for your answer! From my research When I use OpenSsl to connect to the server I get this:
From this we can see that it is using a self signed certificate, however I am using client.ServerCertificateValidationCallback = (s,c,h,e) => true;
client.CheckCertificateRevocation = false; And furthermore, it doesn't make sense to work perfectly on .NET Core 3.1 and not in .NET 5 I have tried with Ubuntu and Alpine ditros, and I appended these lines to
|
Ah, good to know! Looks like, based on your openssl output, that the algorithm name that you used in the config file would be correct. I'm curious, what if you set That might at least tell us if it's getting that far or if it's failing before that check. |
I did that and I can not see the log! It must fail before that |
That suggests that the SslStream hasn't gotten around to validating certificates, yet, then, which supports your theory that it has something to do with negotiating the supported algorithms. |
Looks like .NET 5.0 added AuthenticateAsClientAsync(SslClientAuthenticationOptions, CancellationToken) and SslClientAuthenticationOptions has a CipherSuitesPolicy property that allows setting which cipher algorithms to allow. Maybe I can extend MailKit's IMailService API to allow setting a CipherSuitePolicy as well for NET50. |
Yes that is what I was going to suggest, a way of setting the CipherSuitesPolicy. Setting it at "system default" does not seem to be easy, and also, a developer may want to only allow weak ciphers to a specific mail server, and not to the whole system. Thank you for your time! |
This requires new APIs added in .NET 5 Fixes issue #1140
The above patch should fix this issue. I've got to get back to work, but hopefully some myget packages will be pushed by the automated build system to https://www.myget.org/feed/mimekit/package/nuget/MailKit It'll be v2.10.1.8, I think. There's a new property on each of the Smtp/Pop3/ImapClients called |
Thank you! I will test again when this change is out and I will let you know if it worked. |
Hi, I was looking at your commit and I noticed you have Thank you |
I can confirm that this change fixed the issue. |
Hello,
I recently updated a mailing microservice from .net core 3.1 to .net 5, which runs in a linux docker image, and I keep getting the exception "An error occurred while attempting to establish an SSL or TLS connection."
First I've tried every solution from your FAQ and it still did not work. When I downgrade the service from .NET 5 to .NET core 3.1 it works fine. So it is not the code, and furthermore I am able to connect to google's smtp server with the .NET 5 version.
Having said that, the only options left for me is this breaking change from microsoft Default TLS cipher suites for .NET on Linux.
The server I'm trying to connect to is using TLS1.2 with the cipher AES256-GCM-SHA384, which is not in the list for .NET 5 for Linux from the link above.
I've tried to add the cipher to openssl.cnf in the docker image but without success.
Also, I've tried to set the CipherSuitePolicy for Kestrel and it still did not work.
This is the Smtp.log with .NET 5
Connected to smtp://smtp.mngt.local:587/?starttls=when-available
S: 220 smtp.company-name.pt ESMTP Haraka/2.8.23 ready
C: EHLO [10.42.20.59]
S: 250-smtp.company-name.pt Hello [10.172.16.38]Haraka is at your service.
S: 250-PIPELINING
S: 250-8BITMIME
S: 250-SMTPUTF8
S: 250-SIZE 0
S: 250 STARTTLS
C: STARTTLS
S: 220 Go ahead.
So I'd like to know where is MailKit getting the available ciphers from? Is it something internal? system defaults?
Thank you very much!
The text was updated successfully, but these errors were encountered: