feat: add SMTP provider configuration to support multiple email services

This commit is contained in:
itsscb 2025-03-14 21:52:27 +01:00
parent d971a10cf4
commit cf0d894092
4 changed files with 13 additions and 3 deletions

View File

@ -36,4 +36,5 @@ jobs:
project-id: proj_01JNH9KPMRS34FKC2NHWQ5YNNB
secrets: |
SMTP_MAIL = '${{ secrets.SMTP_MAIL }}'
SMTP_SECRET = '${{ secrets.SMTP_SECRET }}'
SMTP_SECRET = '${{ secrets.SMTP_SECRET }}'
SMTP_PROVIDER = '${{ secrets.SMTP_PROVIDER }}'

View File

@ -47,7 +47,7 @@ pub async fn register(
let credentials = Credentials::new(smtp.mail().to_string(), smtp.secret().to_string());
#[allow(clippy::unwrap_used)]
let mailer = SmtpTransport::relay("smtp.gmail.com")
let mailer = SmtpTransport::relay(smtp.provider())
.unwrap()
.credentials(credentials)
.build();

View File

@ -7,6 +7,7 @@ async fn main(#[shuttle_runtime::Secrets] secrets: SecretStore) -> shuttle_axum:
let smtp_config = digitaler_frieden::config::SMTPConfig::new(
&secrets.get("SMTP_MAIL").expect("SMTP_MAIL not set"),
&secrets.get("SMTP_SECRET").expect("SMTP_SECRET not set"),
&secrets.get("SMTP_PROVIDER").expect("SMTP_PROVIDER not set"),
);
let router = digitaler_frieden::new(smtp_config);
Ok(router.into())

View File

@ -5,13 +5,15 @@ use std::fmt::Debug;
pub struct SMTPConfig {
mail: String,
secret: String,
provider: String,
}
impl SMTPConfig {
pub fn new<T: AsRef<str>>(mail: T, secret: T) -> Self {
pub fn new<T: AsRef<str>>(mail: T, secret: T, provider: T) -> Self {
Self {
mail: mail.as_ref().to_owned(),
secret: secret.as_ref().to_owned(),
provider: provider.as_ref().to_owned(),
}
}
@ -24,12 +26,18 @@ impl SMTPConfig {
pub fn secret(&self) -> &str {
&self.secret
}
#[must_use]
pub fn provider(&self) -> &str {
&self.provider
}
}
impl Debug for SMTPConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SMTPConfig")
.field("mail", &self.mail)
.field("provider", &self.provider)
.field("secret", &"<reducted>")
.finish()
}