Skip to content

Commit 35cf7a1

Browse files
committed
Add Email backend boilerplate
1 parent 0430d2e commit 35cf7a1

File tree

5 files changed

+1865
-73
lines changed

5 files changed

+1865
-73
lines changed

amplify/emails/templates/Welcome.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
3+
import { Body, Html, Text } from "@react-email/components";
4+
5+
export function Welcome(props: Record<string, any>) {
6+
void props;
7+
return (
8+
<Html lang="en">
9+
<Body>
10+
<Text>Welcome to Hack the Change!</Text>
11+
<Text>
12+
You have successfully registered for our event. Please ensure you join
13+
or create a team if you have not already done so.
14+
</Text>
15+
</Body>
16+
</Html>
17+
);
18+
}

amplify/emails/templates/sendEmail.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { SES } from "@aws-sdk/client-ses";
2+
import { render } from "@react-email/render";
3+
4+
import { Welcome } from "./Welcome";
5+
6+
const ses = new SES({ region: process.env.AWS_SES_REGION });
7+
8+
export const EmailTemplateList = {
9+
Welcome: {
10+
template: Welcome,
11+
subject: "Registration Confirmation",
12+
},
13+
};
14+
15+
export const sendEmail = async (
16+
EmailTemplate: keyof typeof EmailTemplateList,
17+
props: Record<string, any>,
18+
toAddress: string,
19+
) => {
20+
const SelectedEmail = EmailTemplateList[EmailTemplate];
21+
const emailHtml = render(SelectedEmail.template(props));
22+
const params = {
23+
Source: "Hack the Change<[email protected]>",
24+
Destination: {
25+
ToAddresses: [toAddress],
26+
},
27+
Message: {
28+
Body: {
29+
Html: {
30+
Charset: "UTF-8",
31+
Data: emailHtml,
32+
},
33+
},
34+
Subject: {
35+
Charset: "UTF-8",
36+
Data: SelectedEmail.subject,
37+
},
38+
},
39+
};
40+
41+
return await ses.sendEmail(params);
42+
};

amplify/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
".next"
44
],
55
"compilerOptions": {
6+
"jsx": "react",
67
/* Visit https://aka.ms/tsconfig to read more about this file */
78

89
/* Projects */

0 commit comments

Comments
 (0)