diff --git a/conf/default.toml b/conf/default.toml index 0870f57..724e090 100644 --- a/conf/default.toml +++ b/conf/default.toml @@ -3,6 +3,8 @@ listen = "[::]:3742" key = "Q^,zH6M}*JY-W[oWCn6T7W!G=TvN,a5[~%cfRKZ7jse1EMDgG7GdTFy)ez*E(9I" [email] -server = "smtp.fastmail.com" -username = "patrick@psbarrett.com" -sender = "Z2A Bot " +server = "smtp.postmarkapp.com" +port = 587 +tls = "StartTls" +username = "PM-T-outbound-Nh7Fw1vnQ3dwi-57cweG5e" +sender = "Z2A Bot " diff --git a/src/conf.rs b/src/conf.rs index fbac645..8a9e903 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -22,9 +22,16 @@ pub struct Email { pub username: String, pub password: String, pub sender: String, + pub tls: Option, pub cert: Option, } +#[derive(Debug, Deserialize, Clone)] +pub enum TlsMode { + Tls, + StartTls, +} + #[derive(Debug, Deserialize, Clone)] #[allow(unused)] pub struct Conf { diff --git a/src/email_client/mod.rs b/src/email_client/mod.rs index 613476d..3bc742c 100644 --- a/src/email_client/mod.rs +++ b/src/email_client/mod.rs @@ -11,7 +11,7 @@ use lettre::{ }; use tokio::time::timeout; -use crate::conf; +use crate::conf::{self, TlsMode}; #[derive(Clone)] pub enum EmailClient { @@ -28,7 +28,12 @@ impl EmailClient { return Ok(EmailClient::Disabled); }; - let mut inner = AsyncSmtpTransport::::relay(&conf.server).unwrap(); + let mut inner = match conf.tls { + Some(TlsMode::Tls) | None => AsyncSmtpTransport::::relay(&conf.server)?, + Some(TlsMode::StartTls) => { + AsyncSmtpTransport::::starttls_relay(&conf.server)? + } + }; if let Some(port) = conf.port { inner = inner.port(port); diff --git a/tests/fixture/mod.rs b/tests/fixture/mod.rs index e1f9e64..ef45b52 100644 --- a/tests/fixture/mod.rs +++ b/tests/fixture/mod.rs @@ -59,6 +59,7 @@ impl TestServer { username: "bot@example.com".to_owned(), password: "1234".to_owned(), sender: "bot@example.com".to_owned(), + tls: None, cert: Some(String::from_utf8_lossy(mock_smtp_server.cert_pem()).to_string()), }), })