# Auth0

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

[Auth0](https://auth0.com) supports custom email providers, so you can route its transactional mail through SendPing. 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 SendPing REST API directly using the global `fetch`.

## Prerequisites

Before you start, you will need:

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

> **Warning:** SendPing raw SMTP listeners are not currently deployed. Use an Auth0 Action that calls the HTTPS API instead of configuring an SMTP provider.

## Send emails with Auth0 Actions

Use an Auth0 Action that calls the SendPing 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 `SENDPING_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://www.sendping.co/api/emails', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${event.secrets.SENDPING_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 SendPing template

Instead of inline `html`, you can reference a published [template](https://www.sendping.co/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://www.sendping.co/api/emails', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${event.secrets.SENDPING_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.
- SendPing [Logs](https://www.sendping.co/docs/logs/overview) show the delivery side: accepted, delivered, opened, bounced.

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