mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
parent
80fc94c4db
commit
dd7e392626
@ -179,7 +179,9 @@ where
|
||||
&token,
|
||||
&data.server_url,
|
||||
&data.mail_options,
|
||||
) {
|
||||
)
|
||||
.await
|
||||
{
|
||||
warn!("Error sending email: {:#?}", e);
|
||||
return Err(TcpError::InternalServerError(format!(
|
||||
"Could not send email: {}",
|
||||
|
@ -1,12 +1,12 @@
|
||||
use crate::infra::{cli::SmtpEncryption, configuration::MailOptions};
|
||||
use anyhow::Result;
|
||||
use anyhow::{Ok, Result};
|
||||
use lettre::{
|
||||
message::Mailbox, transport::smtp::authentication::Credentials, Message, SmtpTransport,
|
||||
Transport,
|
||||
message::Mailbox, transport::smtp::authentication::Credentials, AsyncSmtpTransport,
|
||||
AsyncTransport, Message, Tokio1Executor,
|
||||
};
|
||||
use tracing::debug;
|
||||
|
||||
fn send_email(to: Mailbox, subject: &str, body: String, options: &MailOptions) -> Result<()> {
|
||||
async fn send_email(to: Mailbox, subject: &str, body: String, options: &MailOptions) -> Result<()> {
|
||||
let from = options
|
||||
.from
|
||||
.clone()
|
||||
@ -27,15 +27,15 @@ fn send_email(to: Mailbox, subject: &str, body: String, options: &MailOptions) -
|
||||
options.password.unsecure().to_string(),
|
||||
);
|
||||
let relay_factory = match options.smtp_encryption {
|
||||
SmtpEncryption::TLS => SmtpTransport::relay,
|
||||
SmtpEncryption::STARTTLS => SmtpTransport::starttls_relay,
|
||||
SmtpEncryption::TLS => AsyncSmtpTransport::<Tokio1Executor>::relay,
|
||||
SmtpEncryption::STARTTLS => AsyncSmtpTransport::<Tokio1Executor>::starttls_relay,
|
||||
};
|
||||
let mailer = relay_factory(&options.server)?.credentials(creds).build();
|
||||
mailer.send(&email)?;
|
||||
mailer.send(email).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn send_password_reset_email(
|
||||
pub async fn send_password_reset_email(
|
||||
username: &str,
|
||||
to: &str,
|
||||
token: &str,
|
||||
@ -54,14 +54,15 @@ To reset your password please visit the following URL: {}/reset-password/step2/{
|
||||
Please contact an administrator if you did not initiate the process.",
|
||||
username, domain, token
|
||||
);
|
||||
send_email(to, "[LLDAP] Password reset requested", body, options)
|
||||
send_email(to, "[LLDAP] Password reset requested", body, options).await
|
||||
}
|
||||
|
||||
pub fn send_test_email(to: Mailbox, options: &MailOptions) -> Result<()> {
|
||||
pub async fn send_test_email(to: Mailbox, options: &MailOptions) -> Result<()> {
|
||||
send_email(
|
||||
to,
|
||||
"LLDAP test email",
|
||||
"The test is successful! You can send emails from LLDAP".to_string(),
|
||||
options,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
@ -131,7 +131,16 @@ fn send_test_email_command(opts: TestEmailOpts) -> Result<()> {
|
||||
let to = opts.to.parse()?;
|
||||
let config = infra::configuration::init(opts)?;
|
||||
infra::logging::init(&config)?;
|
||||
mail::send_test_email(to, &config.smtp_options)
|
||||
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()?;
|
||||
|
||||
runtime.block_on(
|
||||
mail::send_test_email(to, &config.smtp_options)
|
||||
.unwrap_or_else(|e| error!("Could not send email: {:#}", e)),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_healthcheck(opts: RunOpts) -> Result<()> {
|
||||
|
Loading…
Reference in New Issue
Block a user