piknik
piknik copied to clipboard
Improve SMTP error given with TLS mismatch
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
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.
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.