1
0
Fork 0
mirror of https://codeberg.org/Mo8it/git-webhook-client synced 2024-11-21 11:06:32 +00:00

Use async lettre

This commit is contained in:
Mo 2022-12-30 14:54:56 +01:00
parent 31f8b44ad9
commit 70e7ef310a
2 changed files with 14 additions and 6 deletions

View file

@ -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"

View file

@ -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(())
}