Skip to main content

Prerequisites

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

1. Create a Deno Deploy project

Go to dash.deno.com/projects and create a new playground project. Screenshot placeholder

2. Edit the handler function

Paste the following code into the browser editor:
main.ts
import { Emailr } from 'npm:emailr';

const emailr = new Emailr('em_xxxxxxxxx');

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

    return new Response(JSON.stringify(response), {
      status: response.error ? 500 : 200,
      headers: {
        'Content-Type': 'application/json',
      },
    });
  } catch (error) {
    console.error(error);
    return new Response(null, {
      status: 500,
    });
  }
});

3. Deploy and send email

Click on Save & Deploy at the top of the screen. Screenshot placeholder

4. Try it yourself

Deno Deploy Example

See the full source code.