Skip to content

Commit 608dae1

Browse files
authored
Email Notification Sending (#5)
1 parent a1613ca commit 608dae1

File tree

9 files changed

+490
-137
lines changed

9 files changed

+490
-137
lines changed

Cargo.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ bitflags = "2.9"
3636
reqwest = { version = "0.12", default-features = false, features = ["default", "json"] }
3737
base64 = "0.22"
3838
tinytemplate = "1.2"
39+
borsh = "1.5"
40+
borsh-derive = "1.5"

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ async fn main() -> Result<()> {
6060
.route("/", delete(blossom::handle_delete))
6161
.route("/notifications/v1/start", post(notification::start))
6262
.route("/notifications/v1/register", post(notification::register))
63+
.route("/notifications/v1/send", post(notification::send))
6364
.route(
6465
"/notifications/confirm_email",
6566
get(notification::confirm_email),

src/notification/email/mod.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,44 @@ pub fn build_email_confirmation_message(
5656
body: rendered,
5757
})
5858
}
59+
60+
#[derive(Serialize)]
61+
struct NotificationContext {
62+
pub logo_link: String,
63+
pub title: String,
64+
pub link: String,
65+
pub preferences_link: String,
66+
}
67+
68+
pub fn build_email_notification_message(
69+
host_url: &url::Url,
70+
preferences_token: &str,
71+
from: &str,
72+
to: &str,
73+
title: &str,
74+
link: &str,
75+
) -> Result<EmailMessage, anyhow::Error> {
76+
let mut tt = TinyTemplate::new();
77+
tt.add_template("mail", template::NOTIFICATION_MAIL_TEMPLATE)?;
78+
79+
// build email preferences link
80+
let preferences_link = host_url
81+
.join(&format!("/notifications/preferences/{}", preferences_token))
82+
.expect("email notification mail");
83+
84+
let context = NotificationContext {
85+
logo_link: get_logo_link(host_url),
86+
title: title.to_owned(),
87+
link: link.to_owned(),
88+
preferences_link: preferences_link.to_string(),
89+
};
90+
91+
let rendered = tt.render("mail", &context)?;
92+
93+
Ok(EmailMessage {
94+
from: from.to_owned(),
95+
to: to.to_owned(),
96+
subject: title.to_owned(),
97+
body: rendered,
98+
})
99+
}

src/notification/email/template.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub const MAIL_CONFIRMATION_TEMPLATE: &str = r#"
5353
</html>
5454
"#;
5555

56-
#[allow(unused)]
5756
pub const NOTIFICATION_MAIL_TEMPLATE: &str = r#"
5857
<!doctype html>
5958
<html lang="en">
@@ -96,11 +95,12 @@ pub const NOTIFICATION_MAIL_TEMPLATE: &str = r#"
9695
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="650" class="container" style="width:650px; max-width:650px;">
9796
<tr><td style="height:44px; line-height:44px;">&nbsp;</td></tr>
9897
</table>
98+
<hr style="border: 1px solid #efefef; width: 600px;" />
9999
<tr>
100100
<td align="center" class="px" style="padding:16px 24px 28px 24px; font-family:Geist, system-ui, sans-serif; font-size:13px; line-height:20px; color:#333333;">
101-
<a href="{notification_link}" style="color:#333333; text-decoration:none;">Manage notification settings</a>
101+
<a href="{preferences_link}" style="color:#333333; text-decoration:none;">Manage notification settings</a>
102102
&nbsp;&nbsp;&nbsp;&nbsp;
103-
<a href="{browser_link}" style="color:#333333; text-decoration:none;">View in the browser</a>
103+
<a href="{link}" style="color:#333333; text-decoration:none;">View in the browser</a>
104104
</td>
105105
</tr>
106106
</table>

0 commit comments

Comments
 (0)