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