mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-11-22 13:16:39 +00:00
Replace invite/reinvite email functions with generic send_email
This commit is contained in:
parent
6e47535c2e
commit
43eb064351
26
src/mail.rs
26
src/mail.rs
@ -5,7 +5,6 @@ use lettre_email::EmailBuilder;
|
|||||||
use native_tls::{Protocol, TlsConnector};
|
use native_tls::{Protocol, TlsConnector};
|
||||||
|
|
||||||
use crate::MailConfig;
|
use crate::MailConfig;
|
||||||
use crate::CONFIG;
|
|
||||||
|
|
||||||
use crate::api::EmptyResult;
|
use crate::api::EmptyResult;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
@ -67,26 +66,7 @@ pub fn send_password_hint(address: &str, hint: Option<String>, config: &MailConf
|
|||||||
.and(Ok(()))
|
.and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_invite(
|
pub fn send_email(address: &str, subject: &str, body: &str, config: &MailConfig) -> EmptyResult {
|
||||||
address: &str,
|
|
||||||
org_id: &str,
|
|
||||||
org_user_id: &str,
|
|
||||||
token: &str,
|
|
||||||
org_name: &str,
|
|
||||||
config: &MailConfig,
|
|
||||||
) -> EmptyResult {
|
|
||||||
let (subject, body) = {
|
|
||||||
(format!("Join {}", &org_name),
|
|
||||||
format!(
|
|
||||||
"<html>
|
|
||||||
<p>You have been invited to join the <b>{}</b> organization.<br><br>
|
|
||||||
<a href=\"{}/#/accept-organization/?organizationId={}&organizationUserId={}&email={}&organizationName={}&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, address, org_name, token
|
|
||||||
))
|
|
||||||
};
|
|
||||||
|
|
||||||
let email = EmailBuilder::new()
|
let email = EmailBuilder::new()
|
||||||
.to(address)
|
.to(address)
|
||||||
.from((config.smtp_from.clone(), "Bitwarden-rs"))
|
.from((config.smtp_from.clone(), "Bitwarden-rs"))
|
||||||
@ -94,10 +74,10 @@ pub fn send_invite(
|
|||||||
.header(("Content-Type", "text/html"))
|
.header(("Content-Type", "text/html"))
|
||||||
.body(body)
|
.body(body)
|
||||||
.build()
|
.build()
|
||||||
.map_err(|e| Error::new("Error building invite email", e.to_string()))?;
|
.map_err(|e| Error::new("Error building email", e.to_string()))?;
|
||||||
|
|
||||||
mailer(config)
|
mailer(config)
|
||||||
.send(email.into())
|
.send(email.into())
|
||||||
.map_err(|e| Error::new("Error sending invite email", e.to_string()))
|
.map_err(|e| Error::new("Error sending email", e.to_string()))
|
||||||
.and(Ok(()))
|
.and(Ok(()))
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user