Skip to main content

Use this pre-built prompt to get started faster.

CursorOpen in Cursor

Prerequisites

To get the most out of this guide, you’ll need to: If you prefer to watch a video, check out our video walkthrough below.

1. Install

Install the Resend Node.js SDK.
npm install resend

2. Install an SSR adapter

Because Astro builds a static site by default, install an SSR adapter to enable on-demand rendering of routes.

3. Add your API key

Create an API key in Resend and add it to your .env file to keep your API key secret.
.env
RESEND_API_KEY="re_xxxxxxxxx"

4. Send email using HTML

Create an Astro Action under actions/index.ts. The easiest way to send an email is with the html parameter.
import { ActionError, defineAction } from 'astro:actions';
import { Resend } from 'resend';

const resend = new Resend(import.meta.env.RESEND_API_KEY);

export const server = {
  send: defineAction({
    accept: 'form',
    handler: async () => {
      const { data, error } = await resend.emails.send({
        from: 'Acme <onboarding@resend.dev>',
        to: ['delivered@resend.dev'],
        subject: 'Hello world',
        html: '<strong>It works!</strong>',
      });

      if (error) {
        throw new ActionError({
          code: 'BAD_REQUEST',
          message: error.message,
        });
      }

      return data;
    },
  }),
};
Call the send action from any frontmatter route, script, or component.

5. Try it yourself

Send Email

Basic email sending

Attachments

Send emails with file attachments

Inline Images (CID)

Embed inline images using CID

Templates

Send emails using Resend hosted templates

Scheduling

Schedule emails for future delivery

Audiences

Manage contacts and audiences

Domains

Create and manage sending domains

Webhooks

Handle webhook events