Prerequisites
To get the most out of this guide, you’ll need to:
1. Install
Get the Resend Node.js SDK.
2. Create an email template
Start by creating your email template on email-template.tsx
.
import * as React from 'react';
interface EmailTemplateProps {
firstName: string;
}
export const EmailTemplate: React.FC<Readonly<EmailTemplateProps>> = ({
firstName,
}) => (
<div>
<h1>Welcome, {firstName}!</h1>
</div>
);
3. Send email using React
Create a new file index.tsx
and send your first email.
import { Resend } from 'resend';
import { EmailTemplate } from './email-template';
const resend = new Resend(process.env.RESEND_API_KEY);
const server = Bun.serve({
port: 3000,
async fetch() {
const { data, error } = await resend.emails.send({
from: 'Acme <onboarding@resend.dev>',
to: ['delivered@resend.dev'],
subject: 'Hello World',
react: EmailTemplate({ firstName: 'Vitor' }),
});
if (error) {
return new Response(JSON.stringify({ error }));
}
return new Response(JSON.stringify({ data }));
},
});
console.log(`Listening on http://localhost:${server.port} ...`);
Start the local server by running bun index.tsx
and navigate to http://localhost:3000
.
3. Try it yourself
Bun Example
See the full source code.