Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

c# - SSL or TLS connection error in MailKit while NOT using SSL or TLS

I am using MailKit to send emails. I don't use SSL or TLS and using port 25. The mail server I am using has port 25 open. What is hapening is that most of the times emails are sent without any problems and sometimes I get the following exception


An error occurred while attempting to establish an SSL or TLS connection.

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. The certificate presented by the server is expired or invalid.

See https://github.com/jstedfast/MailKit/blob/master/FAQ.md#InvalidSslCertificate for possible solutions. MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.

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. The certificate presented by the server is expired or invalid.

Here is the code sample I use

enter image description here


My questions are : 1 - why it tries to use SSL or TLS given that I set not to use it 2 - why it happens randomly

question from:https://stackoverflow.com/questions/66054848/ssl-or-tls-connection-error-in-mailkit-while-not-using-ssl-or-tls

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The ConnectAsync() method that takes a bool useSsl argument only specifies whether the initial connection must use SSL (or, as another way of wording it, it specifies whether the port you are connecting to is SSL-wrapped).

As an example of an SSL-wrapped port, for SMTP that would be port 465.

This option does not tell MailKit whether or not to use the STARTTLS command once the plain-text connection is established.

If you want to disable SSL/TLS completely, use the ConnectAsync() method that takes a SecureSocketOptions argument:

await client.ConnectAsync(m_mailServer, 25, SecureSocketOptions.None);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...