feat: add SMTP provider configuration to support multiple email services
This commit is contained in:
parent
d971a10cf4
commit
cf0d894092
3
.github/workflows/deploy.yml
vendored
3
.github/workflows/deploy.yml
vendored
@ -36,4 +36,5 @@ jobs:
|
|||||||
project-id: proj_01JNH9KPMRS34FKC2NHWQ5YNNB
|
project-id: proj_01JNH9KPMRS34FKC2NHWQ5YNNB
|
||||||
secrets: |
|
secrets: |
|
||||||
SMTP_MAIL = '${{ secrets.SMTP_MAIL }}'
|
SMTP_MAIL = '${{ secrets.SMTP_MAIL }}'
|
||||||
SMTP_SECRET = '${{ secrets.SMTP_SECRET }}'
|
SMTP_SECRET = '${{ secrets.SMTP_SECRET }}'
|
||||||
|
SMTP_PROVIDER = '${{ secrets.SMTP_PROVIDER }}'
|
@ -47,7 +47,7 @@ pub async fn register(
|
|||||||
let credentials = Credentials::new(smtp.mail().to_string(), smtp.secret().to_string());
|
let credentials = Credentials::new(smtp.mail().to_string(), smtp.secret().to_string());
|
||||||
|
|
||||||
#[allow(clippy::unwrap_used)]
|
#[allow(clippy::unwrap_used)]
|
||||||
let mailer = SmtpTransport::relay("smtp.gmail.com")
|
let mailer = SmtpTransport::relay(smtp.provider())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.credentials(credentials)
|
.credentials(credentials)
|
||||||
.build();
|
.build();
|
||||||
|
@ -7,6 +7,7 @@ async fn main(#[shuttle_runtime::Secrets] secrets: SecretStore) -> shuttle_axum:
|
|||||||
let smtp_config = digitaler_frieden::config::SMTPConfig::new(
|
let smtp_config = digitaler_frieden::config::SMTPConfig::new(
|
||||||
&secrets.get("SMTP_MAIL").expect("SMTP_MAIL not set"),
|
&secrets.get("SMTP_MAIL").expect("SMTP_MAIL not set"),
|
||||||
&secrets.get("SMTP_SECRET").expect("SMTP_SECRET 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);
|
let router = digitaler_frieden::new(smtp_config);
|
||||||
Ok(router.into())
|
Ok(router.into())
|
||||||
|
@ -5,13 +5,15 @@ use std::fmt::Debug;
|
|||||||
pub struct SMTPConfig {
|
pub struct SMTPConfig {
|
||||||
mail: String,
|
mail: String,
|
||||||
secret: String,
|
secret: String,
|
||||||
|
provider: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SMTPConfig {
|
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 {
|
Self {
|
||||||
mail: mail.as_ref().to_owned(),
|
mail: mail.as_ref().to_owned(),
|
||||||
secret: secret.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 {
|
pub fn secret(&self) -> &str {
|
||||||
&self.secret
|
&self.secret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn provider(&self) -> &str {
|
||||||
|
&self.provider
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for SMTPConfig {
|
impl Debug for SMTPConfig {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("SMTPConfig")
|
f.debug_struct("SMTPConfig")
|
||||||
.field("mail", &self.mail)
|
.field("mail", &self.mail)
|
||||||
|
.field("provider", &self.provider)
|
||||||
.field("secret", &"<reducted>")
|
.field("secret", &"<reducted>")
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user