mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
try doing an smtp-send timeout
This commit is contained in:
10
src/job.rs
10
src/job.rs
@@ -201,9 +201,17 @@ impl Job {
|
|||||||
println!("{}", String::from_utf8_lossy(&body));
|
println!("{}", String::from_utf8_lossy(&body));
|
||||||
}
|
}
|
||||||
match task::block_on(smtp.send(context, recipients_list, body, self.job_id)) {
|
match task::block_on(smtp.send(context, recipients_list, body, self.job_id)) {
|
||||||
|
Err(crate::smtp::send::Error::SendTimeout(err)) => {
|
||||||
|
warn!(context, "SMTP send timed out {:?}", err);
|
||||||
|
smtp.disconnect();
|
||||||
|
self.try_again_later(
|
||||||
|
TryAgain::AtOnce,
|
||||||
|
Some("send-timeout".to_string()),
|
||||||
|
);
|
||||||
|
}
|
||||||
Err(crate::smtp::send::Error::SendError(err)) => {
|
Err(crate::smtp::send::Error::SendError(err)) => {
|
||||||
// Remote error, retry later.
|
// Remote error, retry later.
|
||||||
info!(context, "SMTP failed to send: {}", err);
|
warn!(context, "SMTP failed to send: {}", err);
|
||||||
smtp.disconnect();
|
smtp.disconnect();
|
||||||
self.try_again_later(TryAgain::AtOnce, Some(err.to_string()));
|
self.try_again_later(TryAgain::AtOnce, Some(err.to_string()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
//! # SMTP message sending
|
//! # SMTP message sending
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use super::Smtp;
|
use super::Smtp;
|
||||||
use async_smtp::*;
|
use async_smtp::*;
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::events::Event;
|
use crate::events::Event;
|
||||||
|
|
||||||
|
/// SMTP send times out after 15 minutes
|
||||||
|
const SEND_TIMEOUT: u64 = 15 * 60;
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(Debug, Fail)]
|
#[derive(Debug, Fail)]
|
||||||
@@ -16,6 +21,14 @@ pub enum Error {
|
|||||||
SendError(#[cause] async_smtp::smtp::error::Error),
|
SendError(#[cause] async_smtp::smtp::error::Error),
|
||||||
#[fail(display = "SMTP has no transport")]
|
#[fail(display = "SMTP has no transport")]
|
||||||
NoTransport,
|
NoTransport,
|
||||||
|
#[fail(display = "SMTP send timed out")]
|
||||||
|
SendTimeout(#[cause] async_std::future::TimeoutError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<async_std::future::TimeoutError> for Error {
|
||||||
|
fn from(err: async_std::future::TimeoutError) -> Error {
|
||||||
|
Error::SendTimeout(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Smtp {
|
impl Smtp {
|
||||||
@@ -44,14 +57,17 @@ impl Smtp {
|
|||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
if let Some(ref mut transport) = self.transport {
|
if let Some(ref mut transport) = self.transport {
|
||||||
transport.send(mail).await.map_err(Error::SendError)?;
|
let res = async_std::future::timeout(Duration::from_secs(SEND_TIMEOUT), async move {
|
||||||
|
transport.send(mail).await.map_err(Error::SendError)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
context.call_cb(Event::SmtpMessageSent(format!(
|
res.map(|_response| {
|
||||||
"Message len={} was smtp-sent to {}",
|
context.call_cb(Event::SmtpMessageSent(format!(
|
||||||
message_len, recipients_display
|
"Message len={} was smtp-sent to {}",
|
||||||
)));
|
message_len, recipients_display
|
||||||
|
)));
|
||||||
Ok(())
|
})
|
||||||
} else {
|
} else {
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
|
|||||||
Reference in New Issue
Block a user