Skip to content

Commit cb4e1c4

Browse files
authored
Feat: add email support (#609)
* feat: add nodemailer, react-email and create basic template and transporter * feat: send thank you email on contact * fix: add aws credentials * feat: add email templates preview
1 parent 90bb96c commit cb4e1c4

File tree

5 files changed

+1042
-24
lines changed

5 files changed

+1042
-24
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Heading, Html } from "@react-email/components";
2+
3+
const ContactTemplate = () => {
4+
return (
5+
<Html lang="en">
6+
<Heading>Thank you for contacting us!</Heading>
7+
</Html>
8+
);
9+
};
10+
11+
export default ContactTemplate;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { SendEmailCommand, SESv2Client } from "@aws-sdk/client-sesv2";
2+
import { render } from "@react-email/components";
3+
import { createTransport } from "nodemailer";
4+
5+
const {
6+
EMAIL_FROM,
7+
AWS_REGION,
8+
EMAIL_AWS_ACCESS_KEY,
9+
EMAIL_AWS_SECRET_ACCESS_KEY,
10+
} = process.env;
11+
12+
const sesClient = new SESv2Client({
13+
region: AWS_REGION,
14+
credentials: {
15+
accessKeyId: EMAIL_AWS_ACCESS_KEY || "",
16+
secretAccessKey: EMAIL_AWS_SECRET_ACCESS_KEY || "",
17+
},
18+
});
19+
20+
const transporter = createTransport({
21+
SES: { sesClient, SendEmailCommand },
22+
});
23+
24+
export const sendEmail = async ({
25+
template,
26+
options: { from, to, subject },
27+
}: {
28+
template: React.ReactNode;
29+
options: {
30+
from?: string;
31+
to: string;
32+
subject: string;
33+
};
34+
}) => {
35+
const emailHtml = await render(template);
36+
37+
await transporter.sendMail({
38+
from: from || EMAIL_FROM,
39+
to,
40+
subject,
41+
html: emailHtml,
42+
});
43+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//import { ContactTemplate } from "@/app/(email-templates)/contact";
2+
//import { sendEmail } from "@/app/(helpers)/email";
13
import { processContact } from "@/app/(helpers)/notion";
24
import { nanoid } from "nanoid";
35
import { NextRequest } from "next/server";
@@ -96,6 +98,11 @@ export async function POST(request: NextRequest) {
9698
source: request.nextUrl.searchParams.get("source") || "Unknown",
9799
});
98100

101+
/* await sendEmail({
102+
template: <ContactTemplate />,
103+
options: { to: email, subject: "Thank you for contacting us!" },
104+
}); */
105+
99106
return new Response(
100107
JSON.stringify({
101108
message: "Success",

apps/contact/package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,27 @@
66
"dev": "next dev --turbopack",
77
"build": "next build",
88
"start": "next start",
9-
"lint": "next lint"
9+
"lint": "next lint",
10+
"emails": "email dev --dir app/\\(email-templates\\)"
1011
},
1112
"dependencies": {
12-
"react": "^19.0.0",
13-
"react-dom": "^19.0.0",
14-
"next": "15.5.2",
13+
"@aws-sdk/client-sesv2": "^3.888.0",
1514
"@notionhq/client": "^5.0.0",
15+
"@react-email/components": "^0.5.3",
1616
"nanoid": "^5.0.9",
17+
"next": "15.5.2",
18+
"nodemailer": "^7.0.6",
19+
"react": "^19.0.0",
20+
"react-dom": "^19.0.0",
1721
"zod": "^4.0.17"
1822
},
1923
"devDependencies": {
20-
"typescript": "^5",
24+
"@react-email/preview-server": "4.2.11",
2125
"@types/node": "^24",
26+
"@types/nodemailer": "^7.0.1",
2227
"@types/react": "^19",
23-
"@types/react-dom": "^19"
28+
"@types/react-dom": "^19",
29+
"react-email": "4.2.11",
30+
"typescript": "^5"
2431
}
2532
}

0 commit comments

Comments
 (0)