mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
server: add option to use insecure SMTP connection
This commit is contained in:
parent
9018e6fa34
commit
d722be8896
@ -113,7 +113,7 @@ key_file = "/data/private_key"
|
||||
#server="smtp.gmail.com"
|
||||
## The SMTP port.
|
||||
#port=587
|
||||
## How the connection is encrypted, either "TLS" or "STARTTLS".
|
||||
## How the connection is encrypted, either "NONE" (no encryption), "TLS" or "STARTTLS".
|
||||
#smtp_encryption = "TLS"
|
||||
## The SMTP user, usually your email address.
|
||||
#user="sender@gmail.com"
|
||||
|
@ -117,6 +117,7 @@ pub struct LdapsOpts {
|
||||
clap::arg_enum! {
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub enum SmtpEncryption {
|
||||
NONE,
|
||||
TLS,
|
||||
STARTTLS,
|
||||
}
|
||||
|
@ -266,6 +266,9 @@ impl ConfigOverrider for SmtpOpts {
|
||||
if let Some(password) = &self.smtp_password {
|
||||
config.smtp_options.password = SecUtf8::from(password.clone());
|
||||
}
|
||||
if let Some(smtp_encryption) = &self.smtp_encryption {
|
||||
config.smtp_options.smtp_encryption = smtp_encryption.clone();
|
||||
}
|
||||
if let Some(tls_required) = self.smtp_tls_required {
|
||||
config.smtp_options.tls_required = Some(tls_required);
|
||||
}
|
||||
|
@ -26,12 +26,21 @@ async fn send_email(to: Mailbox, subject: &str, body: String, options: &MailOpti
|
||||
options.user.clone(),
|
||||
options.password.unsecure().to_string(),
|
||||
);
|
||||
let relay_factory = match options.smtp_encryption {
|
||||
SmtpEncryption::TLS => AsyncSmtpTransport::<Tokio1Executor>::relay,
|
||||
SmtpEncryption::STARTTLS => AsyncSmtpTransport::<Tokio1Executor>::starttls_relay,
|
||||
let mailer = match options.smtp_encryption {
|
||||
SmtpEncryption::NONE => {
|
||||
AsyncSmtpTransport::<Tokio1Executor>::builder_dangerous(&options.server)
|
||||
}
|
||||
SmtpEncryption::TLS => AsyncSmtpTransport::<Tokio1Executor>::relay(&options.server)?,
|
||||
SmtpEncryption::STARTTLS => {
|
||||
AsyncSmtpTransport::<Tokio1Executor>::starttls_relay(&options.server)?
|
||||
}
|
||||
};
|
||||
let mailer = relay_factory(&options.server)?.credentials(creds).build();
|
||||
mailer.send(email).await?;
|
||||
mailer
|
||||
.credentials(creds)
|
||||
.port(options.port)
|
||||
.build()
|
||||
.send(email)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user