kaisellgren / mailer

Compose and send emails from Dart. Supports file attachments, HTML emails and multiple transport methods.
MIT License
166 stars 86 forks source link

TLS issue / STARTTLS support #250

Closed busslina closed 2 months ago

busslina commented 2 months ago

I commented this issue here.

Thanks

Update I:

I think the issue can be related to STARTTLS. If I'm correct, this protocol starts in plain text and then it upgrades to TLS after negotiating it. So this library attempts to stablish a TLS connection when ssl is true. So seems that is not possible to connect to a Postfix server (at least I didn't found how to disable STARTTLS).

Update II:

I thought that Dart didn't support STARTTLS but it seems it can be done this way: https://stackoverflow.com/a/17643296/4681977 https://api.dart.dev/main/627cd3047d2b52e23ba0cd3e31782c0f5ac97e85/dart-io/SecureSocket/secure.html

close2 commented 2 months ago

I've added some more information in https://github.com/dart-lang/sdk/issues/52886

But the TL;DR is: Don't use ssl. mailer will automatically upgrade the connection to an encrypted connection using the smtp command starttls. If the server does not support tls mailer will either continue over an insecure connection if the option allowInsecure is given (off by default) or fail otherwise.

There are very few ssl smtp servers. Usually smtp connections are started over insecure connections and then upgraded to secure ones, using the starttls command.

busslina commented 2 months ago

Cool, thanks. This issue pushed me into studying how SMTP works.

There are very few ssl smtp servers.

My server is one of them and it works great with ssl to true.

So now I fully understand how this package works. Maybe would be a good idea to specify this info on the SmtpServer class documentation.

And thank you again :)