From 0d5f948b5a5d52de08b65ff1a91132e8a2aa1d33 Mon Sep 17 00:00:00 2001 From: pennae Date: Mon, 18 Jul 2022 21:56:40 +0200 Subject: add mail_starttls parameter, default off local mail connections are much preferred for this service, and those needn't be encrypted. --- Rocket.toml | 6 ++++++ src/lib.rs | 3 +++ src/mailer.rs | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Rocket.toml b/Rocket.toml index 85c5abf..26cc045 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -95,6 +95,12 @@ limits.bytes = "128 KiB" # #mail_port = 25 +# mail starttls support (optional) +# +# whether or not to use starttls for mail connections. +# +#mail_starttls = false + # invite only mode (optional) # # if set this instance will run in invite-only mode, disabling public diff --git a/src/lib.rs b/src/lib.rs index ba654c0..29f3e08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,6 +71,8 @@ struct Config { mail_from: Mailbox, mail_host: Option, mail_port: Option, + #[serde(default)] + mail_starttls: bool, #[serde(default)] invite_only: bool, @@ -250,6 +252,7 @@ pub async fn build( config.mail_from.clone(), config.mail_host.as_deref().unwrap_or("localhost"), config.mail_port.unwrap_or(25), + config.mail_starttls, config.location.clone(), ) .context("setting up mail notifications")?, diff --git a/src/mailer.rs b/src/mailer.rs index 18f89b0..7f7ad9f 100644 --- a/src/mailer.rs +++ b/src/mailer.rs @@ -21,6 +21,7 @@ impl Mailer { from: Mailbox, host: &str, port: u16, + starttls: bool, verify_base: Absolute<'static>, ) -> anyhow::Result { Ok(Mailer { @@ -28,7 +29,11 @@ impl Mailer { verify_base, transport: AsyncSmtpTransport::::builder_dangerous(host) .port(port) - .tls(Tls::Opportunistic(TlsParameters::new(host.to_string())?)) + .tls(if starttls { + Tls::Required(TlsParameters::new(host.to_string())?) + } else { + Tls::None + }) .timeout(Some(Duration::from_secs(5))) .build(), }) -- cgit v1.2.3