Skip to main content

Prerequisites

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

1. Install

Get the Emailr Node.js SDK.
npm install emailr

2. Send email using HTML

Create a Server Route under server/api/send.ts. The easiest way to send an email is by using the html parameter.
import { Emailr } from 'emailr';

const emailr = new Emailr(process.env.EMAILR_API_KEY);

export default defineEventHandler(async () => {
  const response = await emailr.emails.send({
    from: 'Acme <[email protected]>',
    to: ['[email protected]'],
    subject: 'Hello world',
    html: '<strong>It works!</strong>',
  });

  if (response.error) {
    throw createError({
      statusCode: 500,
      message: 'Error sending email',
    });
  }

  return response;
});

3. Try it yourself

Nuxt Example

See the full source code.