Learn how you can integrate with the new Server Actions and App Router.
A couple days ago, Next.js 14 was released with a lot of improvements.
One of them is the fact that Server Actions is now stable. Another one is the upgrade to the latest React canary
, which is stable for frameworks.
We're happy to announce that Resend and React Email are compatible with Next.js 14.
Here's how you can leverage the new Server Actions and App Router to send emails.
Get the latest Resend Node.js SDK (v2.0.0
).
Install the latest React Email bundle (v0.0.11
).
Start by creating your own email template on components/email-template.tsx
.
This could be a small component like the one below or a full-blown React Email template.
Create an API file under app/api/send/route.ts
.
Import the React email template and send an email using the react
parameter.
See the full App Router Example on GitHub
Alternatively, you can skip the API Route and define a function that runs securely on the server. That's the new developer experience that Server Actions brings to the table.
First, create a page file under app/page.tsx
.
Then, create a Server Action by defining a function with the "use server"
directive at the top of the function. This will make sure that this piece of code is only ever executed on the server and won't leak your Resend API key to the client.
Import the React email template, and add the logic to send an email using the react
parameter.
Now, add a <form>
element and call the function on the action
attribute.
See the full Server Actions Example on GitHub