# Double opt-in and confirmation emails

> Ask people to confirm their address before they join an audience, and welcome them with a confirmation email. Set the sender, the texts or a custom MJML design, and test both emails.

Each audience can send two emails of its own:

- **Double opt-in**: an email with a confirmation link. People who sign up only join the audience after they click it, so every address on the list belongs to someone who asked to be there.
- **Confirmation email**: a short "you're subscribed" email sent right after someone joins, or after they confirm when double opt-in is on.

Both are off until you turn them on, and both go out from your own verified sending domain.

## Before you begin

- Verify a sending domain. Both emails need a **From** address on one of your [verified domains](/docs/domains/).
- Each email costs one credit, like any other email.
- A workspace that isn't verified yet can only email its own members, so double opt-in emails to other people fail until the workspace is verified.

## Turn on double opt-in

1. **Open the settings.** Go to **Email Marketing → Audiences**, open the audience and select the **Settings** tab.

2. **Set the sender.** In **Double opt-in**, enter a **From** address on a verified domain, such as `News <news@example.com>`, and optionally a **Reply-to**.

3. **Adjust the email.** Change the **Subject**, **Heading**, **Text**, **Button text** and **Footer**, or keep the defaults. The preview on the right updates as you type.

4. **Choose where people land.** Optionally enter a page in **After confirming, go to**. Without it, people see a confirmation page with a link to [manage their subscriptions](/docs/audiences/manage-subscriptions/). It has your [unsubscribe page](/docs/audiences/unsubscribe-page/#other-pages-with-this-design) design and opens in the person's browser language.

5. **Switch it on.** Turn on **Require confirmation** and select **Save**.

Saving fails with "Use an address on a verified sending domain of this workspace." when the **From** domain isn't verified.

### Which sign-ups ask for confirmation

| How the person joins | With double opt-in on |
| --- | --- |
| The audience's [subscribe URL](/docs/audiences/subscribe-url/) | Gets the double opt-in email and joins after clicking its link. The URL returns `202`. |
| A [form](/docs/forms/) that adds people to the audience | Same, unless the form runs its own double opt-in. Then the form's confirmation is enough. If the double opt-in email can't be sent, the form adds the person right away. |
| **Add subscriber** in the dashboard | **Ask them to confirm by email first (double opt-in)** is checked. Clear it to add the person right away. |
| [Add a subscriber](/docs/api-reference/audiences/subscribers/add/) with the API | Only with `"double_opt_in": true`. Without it, the person is added right away. |
| Imports, merges and contact bulk actions | Added right away. |
| The [manage subscriptions page](/docs/audiences/manage-subscriptions/) | Added right away. The link was emailed to the person, which already proves the address. |

### What happens after a sign-up

1. Emailit creates the contact if it's new, without changing an existing contact, and sends the double opt-in email. The person isn't on the audience yet. People who are already subscribed get no email, but the subscribe URL still returns `202`, so it doesn't reveal who is on the list.
2. When they open the link, they join the audience with **Subscribed** on. A `subscriber.created` event is sent and **Added to audience** automations start. The confirmation email follows if it's on.
3. Opening the link again does nothing more. Links expire after 30 days. People who didn't confirm can sign up again to get a new link. Earlier links keep working until they expire, and confirming any one of them is enough. Signing up again right after the first time sends no second email, so the subscribe URL can't be used to flood someone's inbox; the first link keeps working.

The **Settings** tab shows how many people haven't confirmed yet. If the email can't be sent, for example because the domain is no longer verified or the workspace has no credits, the person isn't added and the subscribe URL returns `503`. A form adds the person right away instead, so the sign-up isn't lost, and the submission records the error.

## Send a confirmation email

1. **Open the settings.** On the audience's **Settings** tab, go to **Confirmation email**.

2. **Write the email.** Enter a **From** address on a verified domain, then adjust the texts. Add a **Button text** and **Button link** to point people to your site, or leave them empty for an email without a button.

3. **Switch it on.** Turn on **Send it** and select **Save**.

The confirmation email goes to people who join through the subscribe URL, a form, a double opt-in link or the manage subscriptions page. When you add people yourself, it's only sent when you ask for it: check **Send the confirmation email** in **Add subscriber**, or pass `"send_confirmation_email": true` to the API. Imports and merges never send it.

A confirmation email that fails to send doesn't undo the subscription.

## Variables

The subject, texts and custom designs can use [Temple](/docs/templates/temple/) variables. Contact values are escaped before they go into the email.

| Variable | Value |
| --- | --- |
| `{{confirm_url}}` | The confirmation link. Double opt-in only. |
| `{{manage_subscriptions_url}}` | The person's [manage subscriptions](/docs/audiences/manage-subscriptions/) link. Confirmation email only. |
| `{{audience_name}}` | The audience's public name, or its name when it has none. |
| `{{email}}`, `{{first_name}}`, `{{last_name}}` | The contact's details. Use a default for empty values, such as `{{first_name\|"there"}}`. |

**Text** and **Footer** keep line breaks and accept inline HTML such as `<a>` and `**`. **Heading** and **Button text** are plain text. The double opt-in button always links to `{{confirm_url}}`.

## Design the email in MJML

> **MJML is in alpha:** The MJML visual editor is open only to the Emailit team while we test it. Everyone else uses the default design, with all the texts above. See [MJML editors and API](/docs/templates/mjml/).

To change the layout, select **Customize in the MJML visual editor**. The editor opens with the default design and your current texts. Saving switches the email to **Custom design (MJML)**. Switch **Design** back to **Default design** to use the texts again; the custom design is kept.

A custom double opt-in email must link to `{{confirm_url}}`. Saving one without it fails with "The double opt-in email must link to `{{confirm_url}}`."

## Test the emails

Below each preview, enter an address in **Send a test to** and select **Send test**. The test uses the saved version, so save your changes first. Test emails use sample contact values, and their links don't subscribe anyone.

## Use the API

[Update an audience](/docs/api-reference/audiences/update/) sets both emails. Send only the fields you want to change:

```bash
curl https://api.emailit.com/v2/audiences/aud_5hJ2kL8mNp4Qr \
  -X POST \
  -H "Authorization: Bearer $EMAILIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "double_opt_in": {
      "enabled": true,
      "redirect_url": "https://example.com/welcome",
      "email": { "from": "News <news@example.com>", "subject": "Confirm your subscription to {{audience_name}}" }
    },
    "confirmation_email": {
      "enabled": true,
      "email": { "from": "News <news@example.com>", "button_label": "Read the latest issue", "button_url": "https://example.com/blog" }
    }
  }'
```

Then ask for confirmation when you add someone:

```bash
curl https://api.emailit.com/v2/audiences/aud_5hJ2kL8mNp4Qr/subscribers \
  -X POST \
  -H "Authorization: Bearer $EMAILIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "email": "ada@example.com", "double_opt_in": true }'
```

The response is `202` with `"status": "pending"`. Setting a custom design (`email.source`) through the API is part of the MJML alpha.

## Related

  - [Manage subscriptions page](/docs/audiences/manage-subscriptions/): Let people choose their lists.
  - [Subscribe URL](/docs/audiences/subscribe-url/): Collect sign-ups from your own site.

---
Source: https://emailit.com/docs/audiences/double-opt-in/
