Skip to content

Commit 9220cdd

Browse files
committed
feat: 👽 create boilerplate functions to send the email
1 parent d054441 commit 9220cdd

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RESEND_KEY=""

src/api/emailApi.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const RESEND_KEY = import.meta.env.VITE_RESEND_KEY;
1+
// const RESEND_KEY = import.meta.env.VITE_RESEND_KEY;
22
import { Resend } from "resend";
33
import { Email } from "../../types/emails";
44

5-
const resend = new Resend(RESEND_KEY);
5+
// const resend = new Resend(RESEND_KEY);
6+
const resend = new Resend("re_SDc7pz1Y_KgTU6WSyX1Ed5rtwNHsuFqnG");
67

78
export async function sendEmail(email: Email) {
89
try {

src/api/send/route.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { EmailTemplate } from '../../components/emails/EmailTemplate';
2+
import { Resend } from 'resend';
3+
4+
// const resend = new Resend(process.env.RESEND_API_KEY);
5+
const resend = new Resend("re_SDc7pz1Y_KgTU6WSyX1Ed5rtwNHsuFqnG");
6+
7+
export async function POST() {
8+
try {
9+
const { data, error } = await resend.emails.send({
10+
from: ' <[email protected]>',
11+
to: [
12+
13+
14+
15+
],
16+
subject: "Our Very First Nudgemail",
17+
react: EmailTemplate({ firstName: 'Alex, Dan & Jason' }),
18+
});
19+
20+
if (error) {
21+
return Response.json({ error }, { status: 500 });
22+
}
23+
24+
return Response.json(data);
25+
} catch (error) {
26+
return Response.json({ error }, { status: 500 });
27+
}
28+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
3+
interface EmailTemplateProps {
4+
firstName: string;
5+
}
6+
7+
export const EmailTemplate: React.FC<Readonly<EmailTemplateProps>> = ({
8+
firstName,
9+
}) => (
10+
<div>
11+
<h1>BEACONS LIVES!</h1>
12+
<p>
13+
Hello, {firstName}!
14+
Thankyou for your service. Soon, I will have no further need of you.
15+
</p>
16+
</div>
17+
);

0 commit comments

Comments
 (0)