# Auth0

> Send Auth0 transactional emails — verification codes, password resets, and more — through MailBlastr.

[Auth0](https://auth0.com) supports custom email providers, so you can route its transactional mail through MailBlastr. Authentication flows depend on reliable delivery for verification codes, password resets, and other crucial emails. Auth0 Actions run in a sandboxed Node.js runtime where npm packages cannot be installed, so the examples below call the MailBlastr REST API directly using the global `fetch`.

## Prerequisites

Before you start, you will need:

- A MailBlastr [API key](https://www.mailblastr.com/docs/api-keys/overview).
- A [verified domain](https://www.mailblastr.com/docs/domains/managing) to send from.

## Set up MailBlastr as the email provider

In the Auth0 Dashboard, go to **Branding → Email Provider** and toggle on **Use my own email provider**. Choose the **SMTP** provider and enter your MailBlastr SMTP credentials:

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Host` | string | No | `smtp.mailblastr.com` |
| `Port` | number | No | `587` (STARTTLS) or `465` (SMTPS). |
| `Username` | string | No | `mailblastr` |
| `Password` | string | No | Your API key, e.g. `mb_xxxxxxxxx`. |
| `From` | string | No | An address on your [verified domain](https://www.mailblastr.com/docs/domains/managing). |

Click **Save**, then **Send Test Email** to confirm it works. The message appears in your MailBlastr dashboard and event log. See [Send with SMTP](https://www.mailblastr.com/docs/send-with/smtp) for ports and security details.

## Send emails with Auth0 Actions (optional)

For more control — per-organization sender addresses, conditional routing, or custom logic — use an Auth0 Action that calls the MailBlastr API directly with `fetch`. In the Auth0 Dashboard, go to **Actions → Library** and create a new Custom action.

Store your API key as a secret named `MAILBLASTR_API_KEY` on the Action. The Actions runtime provides a global `fetch` and does not support npm installs, so call the REST API directly. The following example sends a security alert on first login:

**Post Login action**

```js
exports.onExecutePostLogin = async (event, api) => {
  if (event.stats.logins_count !== 1) return;

  await fetch('https://api.mailblastr.com/emails', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${event.secrets.MAILBLASTR_API_KEY}`,
    },
    body: JSON.stringify({
      from: 'Security <security@yourdomain.com>',
      to: event.user.email,
      subject: 'New login detected',
      html: `<p>Hi ${event.user.name}, a new login was detected from ${event.request.ip}.</p>`,
    }),
  });
};
```

Deploy it by adding the Action to the **Post Login** trigger under **Actions → Triggers**.

## Use a MailBlastr template

Instead of inline `html`, you can reference a published [template](https://www.mailblastr.com/docs/templates/overview) and pass variables. The example below uses a template with the id `login-detected` and two variables:

**Post Login action (template)**

```js
exports.onExecutePostLogin = async (event, api) => {
  if (event.stats.logins_count !== 1) return;

  await fetch('https://api.mailblastr.com/emails', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${event.secrets.MAILBLASTR_API_KEY}`,
    },
    body: JSON.stringify({
      from: 'Security <security@yourdomain.com>',
      to: event.user.email,
      template: {
        id: 'login-detected',
        variables: {
          first_name: event.user.name,
          ip_address: event.request.ip,
        },
      },
    }),
  });
};
```

## Debugging email delivery

When something goes wrong, check both sides of the chain:

- **Auth0 Logs** (**Monitoring → Logs**) show send events and any errors raised by the email provider.
- MailBlastr [Logs](https://www.mailblastr.com/docs/logs/overview) show the delivery side: accepted, delivered, opened, bounced.

> **Note:** See the full request body — `cc`, `bcc`, `reply_to`, `tags`, and more — in the [Send an email](https://www.mailblastr.com/docs/api/emails-send) reference.
