cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
692 stars 163 forks source link

Unable to have SmtpServer support Systm.Net.Mail.SmtpClient on Implicit connection over SSL; port 465 #155

Closed everttimmer1963 closed 3 years ago

everttimmer1963 commented 3 years ago

Hello,

I am currently busy implementing a mail server that only receives mails and drops them in a folder. Everything works and I am ablt to connect with either your SmtpClient, and the System.Net.Mail.MailClient.

With the latter one, I am experiencing a problem connecting on port 465, using SSL. The code hangs on Send. This may have someting to do with the System.Net.Mail client not supporting implicit SSL connections.

With your SmtpClient, i can connect succesfully using SecureSocketOptions.SslOnConnect but that option is not available on the Microsoft SmtpClient.

Do you have anything planned to support Explicit SSL connections, Or am I missing a serverside setting?

My configuration: var options = new SmtpServerOptionsBuilder() .Certificate(configuration.Certificate.GetCertificate()) .ServerName(configuration.Binding.ServerName) .Port(25, 587) .Port(465, true) .SupportedSslProtocols(SslProtocols.Tls12 | SslProtocols.Tls13) .Build();

System.Net.Mail.SmtpClient is also used by the Windows Mail application.

cosullivan commented 3 years ago

Hi,

As long as you are providing the certificate then the STARTTLS command should be issues and allow the clients to connect using explicit SSL connections.

Therefore, with your configuration the client should be able to connect to ports 25 and 587 and then optionally issue the STARTTLS command. The only way to force that a STARTTLS command is issued is with a login. For example, if you are requiring authentication (username/passwords) on your server then you can configure it such that the user has to logon first and that the login can only be done in a secure session. In that case, most clients will understand the workflow.

There is no way to force the client to issue the STARTTLS without authentication though. I will look into adding that over the coming week.

If you don't want to use implicit SSL connection on 465 then change the following to false, however that means it will act the same as 587.

.Port(465, false)

everttimmer1963 commented 3 years ago

Thx.

I have been on this most of the day but could not get the System.Net.Mail.SmtpClient working on port 465. I have seen a suggestion about establishing an SSL connection first, and the use the mailclient over that connection but that seems like a weird workaround to send the mail.

Eventually, i was able to just use that client withoud specifying a port, with SSL enabled. It will then establish a connection over port 25 and then issue the STARTTLS command, as shown in the SMTP logger.

I have done some looking around and i get the impression that no one ever succesfully used that client to send a mail to port 465 on any mail server, using authentication or not.

Thanks for your help, mate.