serilog/serilog-sinks-email

Why does the Email sink not use MailKit on Framework?

Closed this issue · 3 comments

The way I'm getting things is that the Email sink uses the deprecated System.Net.Mail.SmtpClient class if run on Framework and MailKit if run on Core or Standard. This behavior doesn't seem documented and I had to read the source code to find this out.

However, SmtpClient is disrecommended by Microsoft:

Important

We don't recommend that you use the SmtpClient class for new development because SmtpClient doesn't support many modern protocols. Use MailKit or other libraries instead. For more information, see SmtpClient shouldn't be used on GitHub.

In particular, SmtpClient does not support authenticating against SMTP servers on port 465. For this reason I was unable to make Serilog.Sinks.Email send emails. MailKit doesn't seem to have this limitation.

Unfortunately, thanks to third party library compatilbility requirements, I'm still stuck on Framework and this is expected to last for about two years.

Considering that MailKit does target Framework I think it would make sense to use MailKit even on Framework projects. Failing that I think it would make sense to add a configuration option to opt in to the use of MailKit even on Framework. In any case I think that the choice of mailing backends depending on .Net version should be explicitly documented.

It does not use Mailkit on Framework:

return new SystemMailEmailTransport(this);

The SystemMailEmailTransport should be removed.

3.0.0-dev-* packages now use MailKit and support all options on .NET Framework.