mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 05:46:29 +03:00
feat(smtp): update to use async-smtp based timeouts
This commit is contained in:
committed by
Alexander Krotov
parent
c1ba5a30c5
commit
2398454838
@@ -1,16 +1,11 @@
|
||||
//! # SMTP message sending
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use super::Smtp;
|
||||
use async_smtp::*;
|
||||
|
||||
use crate::context::Context;
|
||||
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>;
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
@@ -56,18 +51,15 @@ impl Smtp {
|
||||
format!("{}", job_id), // only used for internal logging
|
||||
message,
|
||||
);
|
||||
if let Some(ref mut transport) = self.transport {
|
||||
let res =
|
||||
async_std::future::timeout(Duration::from_secs(SEND_TIMEOUT), transport.send(mail))
|
||||
.await?
|
||||
.map_err(Error::SendError);
|
||||
|
||||
res.map(|_response| {
|
||||
context.call_cb(Event::SmtpMessageSent(format!(
|
||||
"Message len={} was smtp-sent to {}",
|
||||
message_len, recipients_display
|
||||
)));
|
||||
})
|
||||
if let Some(ref mut transport) = self.transport {
|
||||
transport.send(mail).await.map_err(Error::SendError)?;
|
||||
|
||||
context.call_cb(Event::SmtpMessageSent(format!(
|
||||
"Message len={} was smtp-sent to {}",
|
||||
message_len, recipients_display
|
||||
)));
|
||||
Ok(())
|
||||
} else {
|
||||
warn!(
|
||||
context,
|
||||
|
||||
Reference in New Issue
Block a user