35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
|
|
import { ServerClient } from 'postmark'
|
||
|
|
import { POSTMARK_SENDER_ADDRESS, POSTMARK_API_KEY, MAILSHIP_NAME, BASE_URL } from './env.js'
|
||
|
|
import type { Subscription } from './alert.js'
|
||
|
|
import { render } from './templates.js'
|
||
|
|
|
||
|
|
const client = new ServerClient(POSTMARK_API_KEY)
|
||
|
|
|
||
|
|
export const sendConfirm = (sub: Subscription) => {
|
||
|
|
const href = `${BASE_URL}/confirm?token=${sub.key}`
|
||
|
|
|
||
|
|
return client.sendEmail({
|
||
|
|
From: POSTMARK_SENDER_ADDRESS,
|
||
|
|
To: sub.email,
|
||
|
|
Subject: 'Confirm your email digest',
|
||
|
|
HtmlBody: `
|
||
|
|
<h3>Welcome to ${MAILSHIP_NAME}!</h3>
|
||
|
|
<p>Please confirm that you would like to receive ${sub.frequency} digests by clicking the link below:</p>
|
||
|
|
<p><a href="${href}">Confirm Digest</a></p>
|
||
|
|
`,
|
||
|
|
TextBody: `Please confirm that you would like to receive ${sub.frequency} digests by visiting: ${href}`,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
export const sendDigest = async (sub: Subscription, variables: Record<string, any>) => {
|
||
|
|
return client.sendEmail({
|
||
|
|
From: POSTMARK_SENDER_ADDRESS,
|
||
|
|
To: sub.email,
|
||
|
|
Subject: 'New activity',
|
||
|
|
HtmlBody: await render('emails/digest.mjml', {
|
||
|
|
...variables,
|
||
|
|
name: sub.email.split('@')[0],
|
||
|
|
unsubscribeUrl: `${BASE_URL}/unsubscribe?token=${sub.key}`,
|
||
|
|
}),
|
||
|
|
})
|
||
|
|
}
|