diff --git a/src/job.rs b/src/job.rs index 71d29e6fc..db6b4f819 100644 --- a/src/job.rs +++ b/src/job.rs @@ -148,7 +148,6 @@ pub struct Job { pub added_timestamp: i64, pub tries: u32, pub param: Params, - pub pending_error: Option, } impl fmt::Display for Job { @@ -169,7 +168,6 @@ impl Job { added_timestamp: timestamp, tries: 0, param, - pending_error: None, } } @@ -251,12 +249,13 @@ impl Job { smtp.connectivity.set_working(context).await; - let status = match smtp.send(context, recipients, message, job_id).await { + let send_result = smtp.send(context, recipients, message, job_id).await; + smtp.last_send_error = send_result.as_ref().err().map(|e| e.to_string()); + + let status = match send_result { Err(crate::smtp::send::Error::SmtpSend(err)) => { // Remote error, retry later. warn!(context, "SMTP failed to send: {:?}", &err); - smtp.connectivity.set_err(context, &err).await; - self.pending_error = Some(err.to_string()); let res = match err { async_smtp::smtp::error::Error::Permanent(ref response) => { @@ -365,6 +364,7 @@ impl Job { // SMTP server, if not yet done if let Err(err) = smtp.connect_configured(context).await { warn!(context, "SMTP connection failure: {:?}", err); + smtp.last_send_error = Some(format!("SMTP connection failure: {:#}", err)); return Status::RetryLater; } @@ -407,6 +407,8 @@ impl Job { } Err(err) => { warn!(context, "failed to check message existence: {:?}", err); + smtp.last_send_error = + Some(format!("failed to check message existence: {:#}", err)); return Status::RetryLater; } } @@ -521,6 +523,7 @@ impl Job { // connect to SMTP server, if not yet done if let Err(err) = smtp.connect_configured(context).await { warn!(context, "SMTP connection failure: {:?}", err); + smtp.last_send_error = Some(err.to_string()); return Status::RetryLater; } @@ -1321,7 +1324,6 @@ LIMIT 1; added_timestamp: row.get("added_timestamp")?, tries: row.get("tries")?, param: row.get::<_, String>("param")?.parse().unwrap_or_default(), - pending_error: None, }; Ok(job) diff --git a/src/scheduler.rs b/src/scheduler.rs index c67a33a8e..49de54e3f 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -298,7 +298,11 @@ async fn smtp_loop(ctx: Context, started: Sender<()>, smtp_handlers: SmtpConnect None => { // Fake Idle info!(ctx, "smtp fake idle - started"); - connection.connectivity.set_connected(&ctx).await; + match &connection.last_send_error { + None => connection.connectivity.set_connected(&ctx).await, + Some(err) => connection.connectivity.set_err(&ctx, err).await, + } + interrupt_info = idle_interrupt_receiver.recv().await.unwrap_or_default(); info!(ctx, "smtp fake idle - interrupted") } diff --git a/src/smtp.rs b/src/smtp.rs index 7a90ad975..c1556ab10 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -54,6 +54,9 @@ pub(crate) struct Smtp { last_success: Option, pub(crate) connectivity: ConnectivityStore, + + /// If sending the last message failed, contains the error message. + pub(crate) last_send_error: Option, } impl Smtp { @@ -100,20 +103,14 @@ impl Smtp { self.connectivity.set_connecting(context).await; let lp = LoginParam::from_database(context, "configured_").await?; - let res = self - .connect( - context, - &lp.smtp, - &lp.addr, - lp.server_flags & DC_LP_AUTH_OAUTH2 != 0, - lp.provider.map_or(false, |provider| provider.strict_tls), - ) - .await; - - if let Err(err) = &res { - self.connectivity.set_err(context, err).await; - } - res + self.connect( + context, + &lp.smtp, + &lp.addr, + lp.server_flags & DC_LP_AUTH_OAUTH2 != 0, + lp.provider.map_or(false, |provider| provider.strict_tls), + ) + .await } /// Connect using the provided login params.