mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 22:06:29 +03:00
Make Smtp.send async
This commit is contained in:
committed by
Floris Bruynooghe
parent
54eb30f3db
commit
a8e9a1fbe5
@@ -200,7 +200,7 @@ impl Job {
|
|||||||
info!(context, "smtp-sending out mime message:");
|
info!(context, "smtp-sending out mime message:");
|
||||||
println!("{}", String::from_utf8_lossy(&body));
|
println!("{}", String::from_utf8_lossy(&body));
|
||||||
}
|
}
|
||||||
match 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::SendError(err)) => {
|
Err(crate::smtp::send::Error::SendError(err)) => {
|
||||||
// Remote error, retry later.
|
// Remote error, retry later.
|
||||||
smtp.disconnect();
|
smtp.disconnect();
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
use super::Smtp;
|
use super::Smtp;
|
||||||
use async_smtp::*;
|
use async_smtp::*;
|
||||||
|
|
||||||
use async_std::task;
|
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::events::Event;
|
use crate::events::Event;
|
||||||
|
|
||||||
@@ -23,7 +21,7 @@ pub enum Error {
|
|||||||
impl Smtp {
|
impl Smtp {
|
||||||
/// Send a prepared mail to recipients.
|
/// Send a prepared mail to recipients.
|
||||||
/// On successful send out Ok() is returned.
|
/// On successful send out Ok() is returned.
|
||||||
pub fn send(
|
pub async fn send(
|
||||||
&mut self,
|
&mut self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
recipients: Vec<EmailAddress>,
|
recipients: Vec<EmailAddress>,
|
||||||
@@ -47,7 +45,7 @@ impl Smtp {
|
|||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
|
|
||||||
task::block_on(transport.send(mail)).map_err(Error::SendError)?;
|
transport.send(mail).await.map_err(Error::SendError)?;
|
||||||
|
|
||||||
context.call_cb(Event::SmtpMessageSent(format!(
|
context.call_cb(Event::SmtpMessageSent(format!(
|
||||||
"Message len={} was smtp-sent to {}",
|
"Message len={} was smtp-sent to {}",
|
||||||
|
|||||||
Reference in New Issue
Block a user