Skip to content

Commit

Permalink
chore(notification): change email template (#4046)
Browse files Browse the repository at this point in the history
* chore(notification): change email template

* chore(notifications): add from_name for sending emails

---------

Co-authored-by: Vaibhav <[email protected]>
  • Loading branch information
UncleSamtoshi and thevaibhav-dixit authored Feb 22, 2024
1 parent 78aa1d7 commit 6606211
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 389 deletions.
2 changes: 2 additions & 0 deletions core/notifications/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ app:
fcm:
google_application_credentials_path: "./config/notifications/fake_service_account.json"
# email_executor:
# enabled: false
# smtp:
# username: ""
# from_email: ""
# from_name: ""
# relay: ""
# port: 587
# kratos_import:
Expand Down
2 changes: 2 additions & 0 deletions core/notifications/src/email_executor/smtp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub struct SmtpConfig {
#[serde(default)]
pub from_email: String,
#[serde(default)]
pub from_name: String,
#[serde(default)]
pub relay: String,
#[serde(default = "default_smtp_port")]
pub port: u16,
Expand Down
7 changes: 6 additions & 1 deletion core/notifications/src/email_executor/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use error::*;
pub struct SmtpClient {
client: AsyncSmtpTransport<Tokio1Executor>,
from_email: String,
from_name: String,
}

impl SmtpClient {
Expand All @@ -29,6 +30,7 @@ impl SmtpClient {
Ok(Self {
client,
from_email: config.from_email,
from_name: config.from_name,
})
}

Expand All @@ -38,7 +40,10 @@ impl SmtpClient {
recipient_addr: GaloyEmailAddress,
) -> Result<(), SmtpError> {
let email = Message::builder()
.from(Mailbox::new(None, self.from_email.parse()?))
.from(Mailbox::new(
Some(self.from_name.clone()),
self.from_email.parse()?,
))
.to(Mailbox::new(None, recipient_addr.into_inner().parse()?))
.subject(msg.subject)
.header(ContentType::TEXT_HTML)
Expand Down
6 changes: 3 additions & 3 deletions core/notifications/src/messages/email_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ impl EmailFormatter<'_> {
pub fn init() -> Result<Self, MessagesError> {
let mut handlebars = Handlebars::new();
handlebars.register_template_string(
"identification",
"general",
include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/identification.hbs"
"/templates/general.hbs"
)),
)?;
handlebars.register_template_string(
Expand Down Expand Up @@ -44,7 +44,7 @@ impl EmailFormatter<'_> {
"subject": subject,
"body": body,
});
Ok(self.handlebars.render("identification", &data)?)
Ok(self.handlebars.render("general", &data)?)
}
}

Expand Down
19 changes: 19 additions & 0 deletions core/notifications/templates/general.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{#> base}}
<tr>
<td align="center" style="background-color: #fff; padding: 20px">
<h2 style="margin-top: 0; margin-bottom: 20px; font-size: 20px">
{{subject}}
</h2>
<p
style="
margin-top: 0;
margin-bottom: 20px;
font-size: 16px;
line-height: 1.5;
"
>
{{body}}
</p>
</td>
</tr>
{{/base}}
20 changes: 0 additions & 20 deletions core/notifications/templates/identification.hbs

This file was deleted.

63 changes: 45 additions & 18 deletions core/notifications/templates/layouts/base.hbs
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
<!DOCTYPE html>
<html>

<head>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>{{subject}}</title>

{{!-- Include Styles --}}
{{> styles}}
</head>
</head>
<body>
<table role="presentation" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<!-- Centered Content Wrapper -->
<table
class="centered-content"
role="presentation"
cellspacing="0"
cellpadding="0"
>
<!-- Logo Section -->
<tr>
<td class="logo-section" align="center">
<img
src="https://void.cat/d/WhVRCknUEJwCpVCPihYzfU.webp"
alt="Blink - The Everyday Bitcoin Wallet"
width="180"
/>
</td>
</tr>

<body>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="body">
<tr>
<td>&nbsp;</td>
<td class="container">
<div class="content">
{{> @partial-block}}
</div>
</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
<!-- Body Section -->
{{> @partial-block}}

<!-- Footer Section -->
<tr>
<td class="footer-section" align="center">
<p class="footer-text">
This is an automated email. If you encounter problems, please
do not respond to it. Reach out to our
<a href="https://www.blink.sv/en/support">Support</a>
</p>
<br />
<p class="footer-link">
<a href="https://www.blink.sv">blink.sv</a>
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Loading

0 comments on commit 6606211

Please sign in to comment.