diff --git a/config/defaults.hjson b/config/defaults.hjson index 6d7d520a1..bdf19142e 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -76,8 +76,8 @@ smtp_password: "string" # Address to send emails from, eg noreply@your-instance.com smtp_from_address: "noreply@example.com" - # Whether or not smtp connections should use tls. Can be missing (IE None), tls, or starttls - use_tls: "string" + # Whether or not smtp connections should use tls. Can be none, tls, or starttls + tls_type: "none" } # Parameters for automatic configuration of new instance (only used at first start) setup: { diff --git a/crates/utils/src/email.rs b/crates/utils/src/email.rs index b6280927d..69c0fb17b 100644 --- a/crates/utils/src/email.rs +++ b/crates/utils/src/email.rs @@ -77,16 +77,10 @@ pub fn send_email( // Set the TLS let builder_dangerous = SmtpTransport::builder_dangerous(smtp_server).port(smtp_port); - let mut builder = if let Some(tls_type) = email_config.use_tls { - if tls_type == "starttls" { - SmtpTransport::starttls_relay(smtp_server)? - } else if tls_type == "tls" { - SmtpTransport::relay(smtp_server)? - } else { - builder_dangerous - } - } else { - builder_dangerous + let mut builder = match email_config.tls_type.as_str() { + "starttls" => SmtpTransport::starttls_relay(smtp_server)?, + "tls" => SmtpTransport::relay(smtp_server)?, + _ => builder_dangerous, }; // Set the creds if they exist diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index da0526fa0..6e66b92d6 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -101,9 +101,10 @@ pub struct EmailConfig { #[doku(example = "noreply@example.com")] /// Address to send emails from, eg "noreply@your-instance.com" pub smtp_from_address: String, - /// Whether or not smtp connections should use tls. Can be missing (IE None), tls, or starttls - #[default(None)] - pub use_tls: Option, + /// Whether or not smtp connections should use tls. Can be none, tls, or starttls + #[default("none")] + #[doku(example = "none")] + pub tls_type: String, } #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]