Quick setup examples

Deno Deploy

Send your first email from Deno Deploy by calling the MailBlastr API with fetch.

Send your first email from Deno Deploy by calling the MailBlastr REST API. The mailblastr SDK targets Node.js/npm — Deno users POST JSON to https://api.mailblastr.com/emails using the built-in global fetch, so there is nothing to install.

Prerequisites

Before you start, you will need:

1. Create a Deno Deploy project

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

2. Store your API key

In your project's Settings → Environment Variables, add MAILBLASTR_API_KEY with your key, then read it with Deno.env.get.

Environment variable
MAILBLASTR_API_KEY=mb_xxxxxxxxx

3. Edit the handler function

Paste the following code into the browser editor.

main.ts
const MAILBLASTR_API_KEY = Deno.env.get('MAILBLASTR_API_KEY');

Deno.serve(async () => {
  try {
    const res = await fetch('https://api.mailblastr.com/emails', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${MAILBLASTR_API_KEY}`,
      },
      body: JSON.stringify({
        from: 'Acme <onboarding@yourdomain.com>',
        to: ['delivered@example.com'],
        subject: 'Hello World',
        html: '<strong>It works!</strong>',
      }),
    });

    const data = await res.json();

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

4. Deploy and send email

Click Save & Deploy at the top of the screen, then open the deployment URL to verify your email was sent.

See the full set of body fields in the Send an email reference.