mirror of
https://github.com/dani-garcia/vaultwarden
synced 2024-11-12 04:52:47 +01:00
Merge pull request #1143 from BlackDex/better-lettre-errors
Format some common Lettre errors a bit simpler
This commit is contained in:
commit
99da5fbebb
2 changed files with 22 additions and 4 deletions
|
@ -79,7 +79,7 @@ make_error! {
|
||||||
RegexError(RegexErr): _has_source, _api_error,
|
RegexError(RegexErr): _has_source, _api_error,
|
||||||
YubiError(YubiErr): _has_source, _api_error,
|
YubiError(YubiErr): _has_source, _api_error,
|
||||||
|
|
||||||
LetreError(LettreErr): _has_source, _api_error,
|
LettreError(LettreErr): _has_source, _api_error,
|
||||||
AddressError(AddrErr): _has_source, _api_error,
|
AddressError(AddrErr): _has_source, _api_error,
|
||||||
SmtpError(SmtpErr): _has_source, _api_error,
|
SmtpError(SmtpErr): _has_source, _api_error,
|
||||||
FromStrError(FromStrErr): _has_source, _api_error,
|
FromStrError(FromStrErr): _has_source, _api_error,
|
||||||
|
|
24
src/mail.rs
24
src/mail.rs
|
@ -54,7 +54,7 @@ fn mailer() -> SmtpTransport {
|
||||||
for wanted_mechanism in mechanism.split(',') {
|
for wanted_mechanism in mechanism.split(',') {
|
||||||
for m in &allowed_mechanisms {
|
for m in &allowed_mechanisms {
|
||||||
if m.to_string().to_lowercase() == wanted_mechanism.trim_matches(|c| c == '"' || c == '\'' || c == ' ').to_lowercase() {
|
if m.to_string().to_lowercase() == wanted_mechanism.trim_matches(|c| c == '"' || c == '\'' || c == ' ').to_lowercase() {
|
||||||
selected_mechanisms.push(m.clone());
|
selected_mechanisms.push(*m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -330,6 +330,24 @@ fn send_email(address: &str, subject: &str, body_html: &str, body_text: &str) ->
|
||||||
.subject(subject)
|
.subject(subject)
|
||||||
.multipart(alternative)?;
|
.multipart(alternative)?;
|
||||||
|
|
||||||
let _ = mailer().send(&email)?;
|
match mailer().send(&email) {
|
||||||
Ok(())
|
Ok(_) => Ok(()),
|
||||||
|
// Match some common errors and make them more user friendly
|
||||||
|
Err(e) => match e {
|
||||||
|
lettre::transport::smtp::Error::Client(x) => {
|
||||||
|
err!(format!("SMTP Client error: {}", x));
|
||||||
|
},
|
||||||
|
lettre::transport::smtp::Error::Transient(x) => {
|
||||||
|
err!(format!("SMTP 4xx error: {:?}", x.message));
|
||||||
|
},
|
||||||
|
lettre::transport::smtp::Error::Permanent(x) => {
|
||||||
|
err!(format!("SMTP 5xx error: {:?}", x.message));
|
||||||
|
},
|
||||||
|
lettre::transport::smtp::Error::Io(x) => {
|
||||||
|
err!(format!("SMTP IO error: {}", x));
|
||||||
|
},
|
||||||
|
// Fallback for all other errors
|
||||||
|
_ => Err(e.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue