-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send nicer and more meaningful emails. HTML templates with handlebars. Generate screenshots when running tests for visual testing.
- Loading branch information
Showing
20 changed files
with
882 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,7 @@ node_modules | |
database.sqlite | ||
|
||
*.pem | ||
|
||
# Screenshots of emails from testing | ||
screenshots/* | ||
!screenshots/.keep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
import * as nodemailer from 'nodemailer' | ||
import Mail from 'nodemailer/lib/mailer' | ||
import { smtpTransportOptions } from '../config' | ||
import * as path from 'path' | ||
import { appLogo, smtpTransportOptions } from '../config' | ||
|
||
export const sendMail = async (options: Mail.Options) => { | ||
const smtpTransport = nodemailer.createTransport(smtpTransportOptions) | ||
await smtpTransport.sendMail(options) | ||
await smtpTransport.sendMail({ | ||
...options, | ||
attachments: [ | ||
{ | ||
filename: path.basename(appLogo), | ||
path: appLogo, | ||
cid: 'applogo@sleepy.bike', | ||
}, | ||
...(options.attachments ?? []), | ||
], | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as fs from 'fs-extra' | ||
import Handlebars from 'handlebars' | ||
import juice from 'juice' | ||
import path from 'path' | ||
import * as config from '../config' | ||
|
||
Handlebars.registerHelper('encodeURIComponent', encodeURIComponent) | ||
|
||
type LayoutData = { | ||
appName?: string | ||
appLogo?: string | ||
supportEmail?: string | ||
title?: string | ||
} | ||
|
||
export const generateHtmlMessage = async <T>( | ||
type: string, | ||
data: T & LayoutData, | ||
) => { | ||
const layout = await fs.readFile(path.join(__dirname, 'layout.hbs'), 'utf8') | ||
const layoutTemplate = Handlebars.compile(layout) | ||
const content = await fs.readFile(path.join(__dirname, `${type}.hbs`), 'utf8') | ||
const contentTemplate = Handlebars.compile<T>(content) | ||
const stylesheet = await fs.readFile( | ||
path.join(__dirname, 'styles.css'), | ||
'utf8', | ||
) | ||
|
||
const { | ||
appName = config.appName, | ||
appLogo = config.appLogo, | ||
supportEmail = config.supportEmail, | ||
title = '', | ||
} = data | ||
|
||
const compiledContent = contentTemplate({ | ||
...data, | ||
appName, | ||
appLogo, | ||
title, | ||
}) | ||
const emailHtml = layoutTemplate({ | ||
title, | ||
appName, | ||
appLogo, | ||
supportEmail, | ||
body: compiledContent, | ||
}) | ||
const emailHtmlInlineCss = juice(emailHtml, { extraCss: stylesheet }) | ||
|
||
return emailHtmlInlineCss | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<html> | ||
<head> | ||
<meta charset='utf-8' /> | ||
<title>{{title}}</title> | ||
</head> | ||
<body> | ||
<header><img | ||
alt='logo of {{appName}}' | ||
src='cid:applogo@sleepy.bike' | ||
height='32' | ||
/></header> | ||
{{{body}}} | ||
<footer> | ||
<p>You can contact us at | ||
<a href='mailto:{{supportEmail}}'>{{supportEmail}}</a></p> | ||
</footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<p>Hello{{#if target.name}} {{/if}}{{target.name}}!</p> | ||
<p> | ||
<a href={{actor.id}}>{{#if | ||
actor.name | ||
}}{{actor.name}}{{else}}Somebody{{/if}}</a> | ||
sent you a message from | ||
{{appName}}. | ||
</p> | ||
|
||
<blockquote>{{object.content}}</blockquote> | ||
|
||
<a | ||
href='https://sleepy.bike/messages/{{encodeURIComponent actor.id}}' | ||
class='action-button' | ||
>Reply on | ||
{{appName}}</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.action-button { | ||
padding: 0.25rem 0.5rem; | ||
text-align: center; | ||
display: inline-block; | ||
border: 2px solid black; | ||
color: black; | ||
text-decoration: none; | ||
} | ||
|
||
.action-button:hover { | ||
background-color: #e6e6e6; | ||
} | ||
|
||
body { | ||
font-family: Arial, sans-serif; | ||
} | ||
|
||
footer { | ||
margin-top: 2rem; | ||
font-size: 0.9rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<p>To verify your email for | ||
{{appName}} | ||
notifications, please click the following link: | ||
</p> | ||
|
||
<p> | ||
<a href={{{emailVerificationLink}}} class='action-button'> | ||
Verify my email for | ||
{{appName}}</a> | ||
</p> | ||
|
||
<p>If the above link doesn't work, you can try copy-pasting the link directly | ||
into your browser:</p> | ||
|
||
<p | ||
style='overflow-wrap:break-word;word-wrap:break-word' | ||
>{{emailVerificationLink}}</p> | ||
|
||
<p>This email verification for | ||
{{appName}} | ||
was initialized by Solid identity | ||
{{actor}}. If you've received this message unexpectedly and you believe it to | ||
be an error, please ignore it, or contact us for support.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.