feat: add tracing to test mail
This commit is contained in:
parent
c1f31fff7c
commit
f448d31193
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2149,6 +2149,7 @@ dependencies = [
|
||||
"rustls",
|
||||
"socket2 0.5.9",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"url",
|
||||
"webpki-roots 1.0.0",
|
||||
]
|
||||
|
@ -20,7 +20,7 @@ futures-util = "0.3.30"
|
||||
serde_json = "1.0.114"
|
||||
pico-args = "0.5.0"
|
||||
rand = { version = "0.9", features = ["os_rng"] }
|
||||
lettre = { version = "0.11.11", default-features = false, features = ["builder", "smtp-transport", "async-std1-rustls-tls"] }
|
||||
lettre = { version = "0.11.11", default-features = false, features = ["builder", "smtp-transport", "async-std1-rustls-tls", "tracing"] }
|
||||
quick-xml = { version = "0.37", features = ["serde", "serialize"] }
|
||||
actix-web-static-files = "4.0"
|
||||
static-files = "0.2.1"
|
||||
|
@ -14,13 +14,13 @@ mod forgot_password;
|
||||
mod registration;
|
||||
mod testmail;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Mailer {
|
||||
transport: Transports,
|
||||
hostname: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
enum Transports {
|
||||
SmtpTransport(AsyncSmtpTransport<AsyncStd1Executor>),
|
||||
#[allow(unused)]
|
||||
|
@ -1,21 +1,35 @@
|
||||
use lettre::{message::SinglePart, AsyncTransport, Message};
|
||||
use lettre::{
|
||||
message::{Mailbox, SinglePart},
|
||||
Address, AsyncTransport, Message,
|
||||
};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::utils::ApplicationError;
|
||||
|
||||
use super::Mailer;
|
||||
|
||||
impl Mailer {
|
||||
#[instrument]
|
||||
pub async fn send_test_mail(&self, to: &str) -> Result<(), ApplicationError> {
|
||||
let sender_mailbox = Mailbox::new(
|
||||
Some("noreply".to_string()),
|
||||
Address::new("noreply", &self.hostname)?,
|
||||
);
|
||||
|
||||
let message = Message::builder()
|
||||
.from("noreply <noreply@brasiwa-leipzig.de>".parse()?)
|
||||
.reply_to("noreply <noreply@brasiwa-leipzig.de>".parse()?)
|
||||
.from(sender_mailbox.clone())
|
||||
.reply_to(sender_mailbox)
|
||||
.to(to.parse()?)
|
||||
.subject("Brass: Test E-Mail")
|
||||
.singlepart(SinglePart::plain(
|
||||
"Testmail von Brass. E-Mail Versand funktioniert!".to_string(),
|
||||
))?;
|
||||
|
||||
debug!("constructed test message");
|
||||
|
||||
self.transport.send(message).await?;
|
||||
debug!("sent test message");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user