Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-26 05:50:29 +01:00
Add invite email functionality
Dieser Commit ist enthalten in:
Ursprung
680f5e83d8
Commit
e2907f4250
1 geänderte Dateien mit 29 neuen und 0 gelöschten Zeilen
29
src/mail.rs
29
src/mail.rs
|
@ -5,6 +5,7 @@ use lettre::smtp::authentication::Credentials;
|
|||
use lettre_email::EmailBuilder;
|
||||
|
||||
use crate::MailConfig;
|
||||
use crate::CONFIG;
|
||||
|
||||
fn mailer(config: &MailConfig) -> SmtpTransport {
|
||||
let client_security = if config.smtp_ssl {
|
||||
|
@ -60,3 +61,31 @@ pub fn send_password_hint(address: &str, hint: Option<String>, config: &MailConf
|
|||
.map_err(|e| e.to_string())
|
||||
.and(Ok(()))
|
||||
}
|
||||
|
||||
pub fn send_invite(address: &str, org_id: &str, org_user_id: &str, token: &str, org_name: &str, config: &MailConfig) -> Result<(), String> {
|
||||
let (subject, body) = {
|
||||
(format!("Join {}", &org_name),
|
||||
format!(
|
||||
"<html>
|
||||
<p>You have been invited to join the <b>{}</b> organization.<br><br>
|
||||
<a href=\"https://{}/api/organizations/{}/users/{}/accept?token={}\">Click here to join</a></p>
|
||||
<p>If you do not wish to join this organization, you can safely ignore this email.</p>
|
||||
</html>",
|
||||
org_name, CONFIG.domain, org_id, org_user_id, token
|
||||
))
|
||||
};
|
||||
|
||||
let email = EmailBuilder::new()
|
||||
.to(address)
|
||||
.from((config.smtp_from.clone(), "Bitwarden-rs"))
|
||||
.subject(subject)
|
||||
.header(("Content-Type", "text/html"))
|
||||
.body(body)
|
||||
.build()
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
mailer(config)
|
||||
.send(email.into())
|
||||
.map_err(|e| e.to_string())
|
||||
.and(Ok(()))
|
||||
}
|
Laden …
In neuem Issue referenzieren