piknik icon indicating copy to clipboard operation
piknik copied to clipboard

Improve SMTP error given with TLS mismatch

Open UAPTCBlackboard opened this issue 3 years ago • 2 comments

Describe the bug I just ran into this via office365. If you use the docs example of SmtpTransport::relay("smtp.office365.com") it fails. What you need is SmtpTransport::starttls_relay instead. The error you get from attempting to use relay instead, however, is extremely generic and doesn't suggest anything even close to TLS:

error = lettre::transport::smtp::Error {
    kind: Client,
    source: Error(
        None,
    ),
}

The recently closed #632 would also benefit from this I believe!

To Reproduce SmtpTransport::relay("smtp.office365.com")

Expected behavior A more useful error. Something like

error = lettre::transport::smtp::Error {
    kind: Client,
    source: Error(
        TLS,
    ),
}

Environment (please complete the following information):

  • 0.10.0-rc.3
  • OpenSUSE Tumbleweed

UAPTCBlackboard avatar Aug 20 '21 07:08 UAPTCBlackboard

It seems like the r2d2 connection pool is messing up the error source, because compiling without it instead gives Connection error: Network is unreachable (os error 101), which is probably the best we can do here.

SmtpTransport::relay uses a different port from SmtpTransport::starttls_relay, so it's not possible for lettre to know that connecting on a different port would have worked unless we actually tried doing it.

paolobarbolini avatar Aug 25 '21 06:08 paolobarbolini

I did run into something similar like this. If i try to enforce SSL on a connection that doesn't support it and do not have r2d2 enabled, i get an error which i can't seem to parse correctly, since i can't determine the kind of error.

But i think the solution to this is the error.to_string() function which can use the inner and returns some form of readable error output for the client/user.

BlackDex avatar Oct 06 '21 14:10 BlackDex