}
}
-pub fn send_email_to_user(
+pub async fn send_email_to_user(
local_user_view: &LocalUserView,
subject: &str,
body: &str,
&local_user_view.person.name,
body,
settings,
- ) {
+ )
+ .await
+ {
Ok(_o) => _o,
Err(e) => warn!("{}", e),
};
let protocol_and_hostname = settings.get_protocol_and_hostname();
let reset_link = format!("{}/password_change/{}", protocol_and_hostname, &token);
let body = &lang.password_reset_body(reset_link, &user.person.name);
- send_email(subject, email, &user.person.name, body, settings)
+ send_email(subject, email, &user.person.name, body, settings).await
}
/// Send a verification email
let lang = get_interface_language(user);
let subject = lang.verify_email_subject(&settings.hostname);
let body = lang.verify_email_body(&settings.hostname, &user.person.name, verify_link);
- send_email(&subject, new_email, &user.person.name, &body, settings)?;
+ send_email(&subject, new_email, &user.person.name, &body, settings).await?;
Ok(())
}
.unwrap_or(false)
}
-pub fn send_application_approved_email(
+pub async fn send_application_approved_email(
user: &LocalUserView,
settings: &Settings,
) -> Result<(), LemmyError> {
let lang = get_interface_language(user);
let subject = lang.registration_approved_subject(&user.person.actor_id);
let body = lang.registration_approved_body(&settings.hostname);
- send_email(&subject, email, &user.person.name, &body, settings)
+ send_email(&subject, email, &user.person.name, &body, settings).await
}
/// Send a new applicant email notification to all admins
let lang = get_interface_language_from_settings(admin);
let subject = lang.new_application_subject(&settings.hostname, applicant_username);
let body = lang.new_application_body(applications_link);
- send_email(&subject, email, &admin.person.name, &body, settings)?;
+ send_email(&subject, email, &admin.person.name, &body, settings).await?;
}
Ok(())
}
let lang = get_interface_language_from_settings(admin);
let subject = lang.new_report_subject(&settings.hostname, reported_username, reporter_username);
let body = lang.new_report_body(reports_link);
- send_email(&subject, email, &admin.person.name, &body, settings)?;
+ send_email(&subject, email, &admin.person.name, &body, settings).await?;
}
Ok(())
}
message::{Mailbox, MultiPart},
transport::smtp::{authentication::Credentials, extension::ClientId},
Address,
+ AsyncTransport,
Message,
- SmtpTransport,
- Transport,
};
use std::str::FromStr;
use uuid::Uuid;
rosetta_i18n::include_translations!();
}
-pub fn send_email(
+type AsyncSmtpTransport = lettre::AsyncSmtpTransport<lettre::Tokio1Executor>;
+
+pub async fn send_email(
subject: &str,
to_email: &str,
to_username: &str,
// is bad.
// Set the TLS
- let builder_dangerous = SmtpTransport::builder_dangerous(smtp_server).port(smtp_port);
+ let builder_dangerous = AsyncSmtpTransport::builder_dangerous(smtp_server).port(smtp_port);
let mut builder = match email_config.tls_type.as_str() {
- "starttls" => SmtpTransport::starttls_relay(smtp_server)?,
- "tls" => SmtpTransport::relay(smtp_server)?,
+ "starttls" => AsyncSmtpTransport::starttls_relay(smtp_server)?,
+ "tls" => AsyncSmtpTransport::relay(smtp_server)?,
_ => builder_dangerous,
};
let mailer = builder.hello_name(ClientId::Domain(domain)).build();
- let result = mailer.send(&email);
+ let result = mailer.send(email).await;
match result {
Ok(_) => Ok(()),