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:
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"] }
|
diesel_migrations = { version = "2.0.0", features = ["sqlite"] }
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
hmac = "0.12"
|
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 = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_yaml = "0.9"
|
serde_yaml = "0.9"
|
||||||
|
|
|
@ -2,15 +2,20 @@ use anyhow::{Context, Result};
|
||||||
use lettre::{
|
use lettre::{
|
||||||
address::Address,
|
address::Address,
|
||||||
message::{Mailbox, Message, MessageBuilder},
|
message::{Mailbox, Message, MessageBuilder},
|
||||||
transport::{smtp::authentication::Credentials, Transport},
|
transport::{
|
||||||
SmtpTransport,
|
smtp::{authentication::Credentials, AsyncSmtpTransport},
|
||||||
|
AsyncTransport,
|
||||||
|
},
|
||||||
|
Tokio1Executor,
|
||||||
};
|
};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
||||||
|
type ASmtpTransport = AsyncSmtpTransport<Tokio1Executor>;
|
||||||
|
|
||||||
pub struct Mailer {
|
pub struct Mailer {
|
||||||
mailer: SmtpTransport,
|
mailer: ASmtpTransport,
|
||||||
message_builder: MessageBuilder,
|
message_builder: MessageBuilder,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +26,7 @@ impl Mailer {
|
||||||
mem::take(&mut config.email_server.password),
|
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!")?
|
.context("Failed to connect to the email server!")?
|
||||||
.credentials(creds)
|
.credentials(creds)
|
||||||
.build();
|
.build();
|
||||||
|
@ -52,7 +57,10 @@ impl Mailer {
|
||||||
.body(hook_log_link.to_string())
|
.body(hook_log_link.to_string())
|
||||||
.context("Failed to build email!")?;
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue