1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { email as sendEmail } from "https://esm.town/v/std/email?v=11";
interface VerificationEmailParams {
emailAddress: string;
html: string;
}
export async function sendVerificationEmail({ emailAddress, html }: VerificationEmailParams) {
try {
// email a confirmation link to the subscriber
await sendEmail({
to: emailAddress,
from: {
name: "Pete Millspaugh",
email: "petermillspaugh.sendVerificationEmail@valtown.email",
},
replyTo: "pete@petemillspaugh.com",
subject: "Confirm your subscription to petemillspaugh.com",
html,
});
// email myself a success notification
await sendEmail({
subject: `${emailAddress} subscribed to petemillspaugh.com`,
text: `A notification for ${emailAddress} verification should come in any minute now.`,
});
} catch (error) {
const { name, message, stack } = error;
await sendEmail({
subject: `Error sending email verification to ${emailAddress}`,
html: `
<pre>
<code>
${name}
${message}
${stack}
</code>
</pre>
`,
});
}
}