mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
server: add an option to use STARTTLS for smtp
This commit is contained in:
parent
cd0ab378ef
commit
8c1ea11b95
@ -1,4 +1,4 @@
|
||||
use crate::infra::configuration::MailOptions;
|
||||
use crate::infra::{cli::SmtpEncryption, configuration::MailOptions};
|
||||
use anyhow::Result;
|
||||
use lettre::{
|
||||
message::Mailbox, transport::smtp::authentication::Credentials, Message, SmtpTransport,
|
||||
@ -26,9 +26,11 @@ fn send_email(to: Mailbox, subject: &str, body: String, options: &MailOptions) -
|
||||
options.user.clone(),
|
||||
options.password.unsecure().to_string(),
|
||||
);
|
||||
let mailer = SmtpTransport::relay(&options.server)?
|
||||
.credentials(creds)
|
||||
.build();
|
||||
let relay_factory = match options.smtp_encryption {
|
||||
SmtpEncryption::TLS => SmtpTransport::relay,
|
||||
SmtpEncryption::STARTTLS => SmtpTransport::starttls_relay,
|
||||
};
|
||||
let mailer = relay_factory(&options.server)?.credentials(creds).build();
|
||||
mailer.send(&email)?;
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user