mirror of
https://codeberg.org/Mo8it/git-webhook-client
synced 2024-12-13 13:56:09 +00:00
Use async lettre
This commit is contained in:
parent
31f8b44ad9
commit
70e7ef310a
2 changed files with 14 additions and 6 deletions
|
@ -18,7 +18,7 @@ diesel = { version = "2.0", features = ["r2d2", "sqlite", "returning_clauses_for
|
|||
diesel_migrations = { version = "2.0.0", features = ["sqlite"] }
|
||||
hex = "0.4"
|
||||
hmac = "0.12"
|
||||
lettre = { version = "0.10", default-features = false, features = ["smtp-transport", "hostname", "rustls-tls", "pool", "builder"] }
|
||||
lettre = { version = "0.10", default-features = false, features = ["smtp-transport", "hostname", "tokio1-rustls-tls", "pool", "builder"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
serde_yaml = "0.9"
|
||||
|
|
|
@ -2,15 +2,20 @@ use anyhow::{Context, Result};
|
|||
use lettre::{
|
||||
address::Address,
|
||||
message::{Mailbox, Message, MessageBuilder},
|
||||
transport::{smtp::authentication::Credentials, Transport},
|
||||
SmtpTransport,
|
||||
transport::{
|
||||
smtp::{authentication::Credentials, AsyncSmtpTransport},
|
||||
AsyncTransport,
|
||||
},
|
||||
Tokio1Executor,
|
||||
};
|
||||
use std::mem;
|
||||
|
||||
use crate::config;
|
||||
|
||||
type ASmtpTransport = AsyncSmtpTransport<Tokio1Executor>;
|
||||
|
||||
pub struct Mailer {
|
||||
mailer: SmtpTransport,
|
||||
mailer: ASmtpTransport,
|
||||
message_builder: MessageBuilder,
|
||||
}
|
||||
|
||||
|
@ -21,7 +26,7 @@ impl Mailer {
|
|||
mem::take(&mut config.email_server.password),
|
||||
);
|
||||
|
||||
let mailer = SmtpTransport::relay(&config.email_server.server_name)
|
||||
let mailer = ASmtpTransport::relay(&config.email_server.server_name)
|
||||
.context("Failed to connect to the email server!")?
|
||||
.credentials(creds)
|
||||
.build();
|
||||
|
@ -52,7 +57,10 @@ impl Mailer {
|
|||
.body(hook_log_link.to_string())
|
||||
.context("Failed to build email!")?;
|
||||
|
||||
self.mailer.send(&email).context("Failed to send email!")?;
|
||||
self.mailer
|
||||
.send(email)
|
||||
.await
|
||||
.context("Failed to send email!")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue