summaryrefslogtreecommitdiff
path: root/src/mailer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailer.rs')
-rw-r--r--src/mailer.rs27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/mailer.rs b/src/mailer.rs
index 7f7ad9f..8e48db0 100644
--- a/src/mailer.rs
+++ b/src/mailer.rs
@@ -2,7 +2,10 @@ use std::time::Duration;
use lettre::{
message::Mailbox,
- transport::smtp::client::{Tls, TlsParameters},
+ transport::smtp::{
+ authentication::Credentials,
+ client::{Tls, TlsParameters},
+ },
AsyncSmtpTransport, Message, Tokio1Executor,
};
use rocket::http::uri::Absolute;
@@ -22,20 +25,24 @@ impl Mailer {
host: &str,
port: u16,
starttls: bool,
+ credentials: Option<Credentials>,
verify_base: Absolute<'static>,
) -> anyhow::Result<Self> {
+ let transport = AsyncSmtpTransport::<Tokio1Executor>::builder_dangerous(host)
+ .port(port)
+ .tls(if starttls {
+ Tls::Required(TlsParameters::new(host.to_string())?)
+ } else {
+ Tls::None
+ })
+ .timeout(Some(Duration::from_secs(5)));
Ok(Mailer {
from,
verify_base,
- transport: AsyncSmtpTransport::<Tokio1Executor>::builder_dangerous(host)
- .port(port)
- .tls(if starttls {
- Tls::Required(TlsParameters::new(host.to_string())?)
- } else {
- Tls::None
- })
- .timeout(Some(Duration::from_secs(5)))
- .build(),
+ transport: match credentials {
+ None => transport.build(),
+ Some(c) => transport.credentials(c).build(),
+ },
})
}