# Transactional and marketing mail

> How the message category changes what the relay adds to each message, how one-click unsubscribe works, and how to set the default.

Source: https://www.coritan.com/docs/mail/smtp-relay/message-categories/

Every message SMTP Relay sends is either *transactional* or *marketing*. The category decides whether the relay adds *one-click unsubscribe* headers, which let the recipient's mail app show an unsubscribe button. Gmail and Yahoo ask for those headers on bulk mail.

Transactional
: Mail a person expects because of something they did: receipts, alerts, password resets, sign-in codes. The relay sends it as your application wrote it.

Marketing
: Newsletters, announcements and campaigns. The relay adds unsubscribe headers, and over the send API it sends each recipient a separate copy.

## How a message gets its category

The relay reads the first of these that is set:

1. Over the [send API](/docs/mail/smtp-relay/send-with-the-api/), the `category` field: `transactional` or `marketing`. The API refuses any other value.
2. Over [SMTP](/docs/mail/smtp-relay/credentials/), the header `X-Mail-Category: marketing` or `X-Mail-Category: transactional`. Case does not matter.
3. The relay's *default category*, which starts as transactional.

Over SMTP, an `X-Mail-Category` header with any other value, such as `newsletter`, makes the message transactional, whatever the default.

## What marketing adds

Each marketing message gets two headers:

```text
List-Unsubscribe: <https://api.coritan.com/api/v1/mail/unsubscribe/{token}>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
```

The link points at our API. Its `{token}` is signed, and names the relay and the one recipient the copy is for. Because the link belongs to one person, how the relay adds it depends on how the message arrives.

Over the send API
: The relay sends each address in `to` and `cc` its own copy, addressed to that person alone, with its own link. The headers replace any `List-Unsubscribe` pair you put in `headers`. The message also carries `X-Mail-Category: marketing`.

Over SMTP
: The relay adds the headers only to a message with exactly one recipient and no `List-Unsubscribe` header of its own. A message with several recipients goes out as it is, without unsubscribe headers, because one link cannot name them all. For bulk mail over SMTP, send one message per recipient, or add your own `List-Unsubscribe` headers.

A transactional message gets no unsubscribe headers from the relay. Over the send API it carries `X-Mail-Category: transactional`, and any `List-Unsubscribe` pair you add in `headers` is kept.

## What an unsubscribe does

When the recipient selects the unsubscribe button, their mail app posts to the link, as RFC 8058 describes. Someone who opens the link in a browser gets the same result. Either way:

- We add the address to the relay's [suppression list](/docs/mail/smtp-relay/suppressions/) with the reason `unsubscribe`.
- The page says `alex@example.com will not receive further marketing email from this sender.`
- Selecting the link again changes nothing.

> [!IMPORTANT]
> A suppressed address receives nothing from the relay, transactional mail included, even though the page mentions only marketing email. The relay drops it from every message sent over the API and refuses it as a recipient over SMTP. If the person later needs a receipt or a password reset, [remove them from the suppression list](/docs/mail/smtp-relay/suppressions/#remove-an-address) once they ask to hear from you again.

The unsubscribe covers the whole relay, every sending domain included. A link does not expire.

## Set the default category

The default applies to every message that does not set a category. On the relay's **Overview** tab, in the **Deliverability** card, choose **Default message category**. A toast confirms the change, such as `Default category is now marketing.` It applies to messages sent from then on.

Set it to marketing only when most of what the relay sends is bulk mail, and mark receipts and other transactional messages as `transactional` one by one. A Mail Hosting service has its own default, on its **Settings** tab: see [Mail Hosting settings](/docs/mail/mail-hosting/settings/#set-the-default-message-category).

## With the API

Set the relay's default category:

```bash
curl -X PATCH https://api.coritan.com/api/v1/client/smtp-relay/4812/category \
  -H "Authorization: Bearer $CORITAN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"default_category": "marketing"}'
```

`default_category` is `transactional` or `marketing`; any other value answers `422`. The answer is the new default:

```json
{"default_category": "marketing"}
```

The unsubscribe link is `GET` or `POST /mail/unsubscribe/{token}`. It needs no key or token of yours, ignores the request body, and answers `200` with the plain-text sentence above. A link that has been changed or cut short answers `404` `Unknown unsubscribe link`. Your application does not call it: receiving mail apps and recipients do.

## API

- `PATCH /api/v1/client/smtp-relay/{service_id}/category`: Set category (https://www.coritan.com/docs/api/reference/client/mail/smtp-relay/#op-patch-api-v1-client-smtp-relay-service-id-category)
- `GET /api/v1/mail/unsubscribe/{token}`: RFC 8058 target (https://www.coritan.com/docs/api/reference/client/mail-send-api/#op-get-api-v1-mail-unsubscribe-token)
- `POST /api/v1/mail/unsubscribe/{token}`: RFC 8058 target (https://www.coritan.com/docs/api/reference/client/mail-send-api/#op-post-api-v1-mail-unsubscribe-token)
