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 anyhow::Result;
|
||||||
use lettre::{
|
use lettre::{
|
||||||
message::Mailbox, transport::smtp::authentication::Credentials, Message, SmtpTransport,
|
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.user.clone(),
|
||||||
options.password.unsecure().to_string(),
|
options.password.unsecure().to_string(),
|
||||||
);
|
);
|
||||||
let mailer = SmtpTransport::relay(&options.server)?
|
let relay_factory = match options.smtp_encryption {
|
||||||
.credentials(creds)
|
SmtpEncryption::TLS => SmtpTransport::relay,
|
||||||
.build();
|
SmtpEncryption::STARTTLS => SmtpTransport::starttls_relay,
|
||||||
|
};
|
||||||
|
let mailer = relay_factory(&options.server)?.credentials(creds).build();
|
||||||
mailer.send(&email)?;
|
mailer.send(&email)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user