Skip to content

Latest commit

 

History

History
53 lines (34 loc) · 1.36 KB

QUICKSTART.md

File metadata and controls

53 lines (34 loc) · 1.36 KB

Astro

Learn how to send your first email using Astro and the Resend Node.js SDK.

Prerequisites

To get the most out of this guide, you’ll need to:

1. Install

Get the Resend Node.js SDK.

TODO: package manager tabs

2. Send emails using HTML

Create and Endpoint under src/pages/api/send.ts.

The easiest way to send an email is by using the html parameter.

import type { APIRoute } from "astro";
import { Resend } from "resend";

// Only needed in hybrid mode
export const prerender = false;

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

export const POST: APIRoute = async () => {
  const { data, error } = await resend.emails.send({
    from: "Acme <[email protected]>",
    to: ["[email protected]"],
    subject: "Hello world",
    html: "<strong>It works!</strong>",
  });

  if (error) {
    return new Response(JSON.stringify({ error }), { status: 400 });
  }

  return new Response(JSON.stringify(data), { status: 200 });
};

3. Try it yourself

TODO: card to https://github.com/resend/resend-astro-example