Node.js library for the Resend API
npm install resend
Framework guides
- Next.js
- Remix
- Nuxt
- Express
- RedwoodJS
- Hono
- Bun
- Astro
Node.js library for the Resend API.
``bash`
npm install resendor
yarn add resend
Send email with:
- Node.js
- Next.js (App Router)
- Next.js (Pages Router)
- Express
First, you need to get an API key, which is available in the Resend Dashboard.
`js`
import { Resend } from 'resend';
const resend = new Resend('re_xxxx...xxxxxx');
Send your first email:
`js
const { data } = await resend.emails.send({
from: 'you@example.com',
to: 'user@gmail.com',
replyTo: 'you@example.com',
subject: 'hello world',
text: 'it works!',
});
console.log(Email ${data.id} has been sent);`
> [!NOTE]
> In order to send from your own domain, you will first need to verify your domain in the Resend Dashboard.
Send an email custom HTML content:
`js
const { data } = await resend.emails.send({
from: 'you@example.com',
to: 'user@gmail.com',
replyTo: 'you@example.com',
subject: 'hello world',
html: 'it works!',
});
console.log(Emaill ${data.id} with customer HTML content has been sent.);`
Start by creating your email template as a React component.
`jsx
import React from 'react';
export default function EmailTemplate({ firstName, product }) {
return (
Thanks for trying {product}. We’re thrilled to have you on board.
Then import the template component and pass it to the
react property.`jsx
import EmailTemplate from '../components/EmailTemplate';const { data } = await resend.emails.send({
from: 'you@example.com',
to: 'user@gmail.com',
replyTo: 'you@example.com',
subject: 'hello world',
react: ,
});
console.log(
Email ${data.id} with a React template has been sent);
`> [!NOTE]
> If you're sending emails from a file that doesn't have JSX transpilation set up (e.g., in a
.js/.ts file instead of JSX/TSX), use React's jsx runtime function instead of passing the component as JSX:
>
>`js
>import { jsx } from 'react/jsx-runtime'
>import EmailTemplate from '../components/EmailTemplate';
>
>await resend.emails.send({
> from: 'you@example.com',
> to: 'user@gmail.com',
> replyTo: 'you@example.com',
> subject: 'hello world',
> react: jsx(EmailTemplate, { firstName:"John", product:"MyApp" }),
>});
>``MIT License