> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sellauth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Email Templates

> Rewrite the emails your shop sends: the subject, the body, the shared layout, and the variables each one receives.

Every customer-facing email your shop sends is a Nunjucks template you can replace. Templates are edited under [**E-mail Settings**](https://dash.sellauth.com/email/templates), and each one starts from a SellAuth default until you override it.

Editing templates requires a plan that includes it. For connecting your own sending server, see [Email Settings](/guides/email-settings).

## Structure

A template supplies two things: a subject and a body. Both are written as `block` tags, which is how SellAuth splits a single file into those two parts. You do not extend anything or write an HTML document, because the shared layout provides them.

```njk theme={null}
{% block subject %}
  {{ shop.name }} - Order Completed
{% endblock %}

{% block content %}
  <p>Your order on <strong>{{ shop.name }}</strong> is ready.</p>
{% endblock %}
```

The `subject` block becomes the subject line and is rendered as plain text. The `content` block is the body, and is inserted into the shared layout. Both are required.

## The base layout

**Base Layout** is a template like any other, and it wraps every email your shop sends. It carries the document, the styles, your shop's branding header, the social links footer and the unsubscribe link, and it renders each email's body where it says:

```njk theme={null}
{{ templateContent | safe }}
```

Editing the layout changes every email at once, so it is where branding belongs: colours, fonts, header, footer. It only receives `shop`, so anything invoice-specific has to go in the individual template.

<Warning>
  Email clients are far less capable than browsers. Table-based layouts and inline styles are used throughout the defaults for a reason, and a layout written like a modern web page will break in Outlook. Start from the default and change it rather than replacing it wholesale.
</Warning>

## Available templates

Each template receives its own set of variables, listed below. `shop` is available everywhere.

### Invoices

| Template | Sent when | Variables |
| - | - | - |
| Invoice Created | An invoice is created | `invoice`, `customer` |
| Invoice Processed | An invoice is paid and processed | `invoice`, `feedback`, `customer` |
| Invoice Replacement Issued | You replace a delivered item | `invoice`, `feedback`, `customer`, `replacements` |
| Invoice Shipped | A physical invoice is marked shipped | `invoice`, `customer` |
| Invoice Delivered | A physical invoice is marked delivered | `invoice`, `customer` |
| Service Started | A service invoice is marked in progress | `invoice`, `customer`, `message` |
| Service Completed | A service invoice is completed | `invoice`, `customer`, `message` |

### Feedback

| Template | Sent when | Variables |
| - | - | - |
| Feedback Reply | You reply to a review | `invoice`, `feedback`, `customer` |
| Feedback Coupon Reward | A review earns the buyer a coupon | `invoice`, `customer`, `feedback`, `coupons` |
| Feedback Dispute Accepted | A review dispute is upheld | `invoice`, `feedback`, `customer` |

### Subscriptions

| Template | Sent when | Variables |
| - | - | - |
| Subscription Started | A subscription begins | `subscription`, `customer` |
| Subscription Renewal Due | A manual renewal is coming up | `subscription`, `invoice`, `customer` |
| Subscription Payment Failed | An automatic renewal fails | `subscription`, `customer`, `payment_url` |
| Subscription Cancelled | A subscription is cancelled | `subscription`, `customer` |
| Subscription Expired | A subscription ends without renewing | `subscription`, `customer` |

### Support and account

| Template | Sent when | Variables |
| - | - | - |
| Customer Login Code | A customer signs in to their account | `customer`, `otp` |
| Ticket Message | A message is added to a ticket | `ticket`, `lastMessage`, `invoice`, `customer` |
| Ticket Closed | A ticket is closed | `ticket`, `lastMessage`, `invoice`, `customer` |
| Withdrawal Request Received | A customer submits a withdrawal request | `invoice`, `customer` |

### Growth

| Template | Sent when | Variables |
| - | - | - |
| Abandoned Checkout Recovery | You send a recovery email | `invoice`, `customer`, `coupon` |
| Affiliate Payout Processed | You record an affiliate payout | `customer`, `payout` |
| Reseller Application Approved | You approve a reseller | `customer` |
| Reseller Application Rejected | You reject a reseller | `customer` |

## Helpers

Email templates get **no** SellAuth theme filters. The full helper set is:

| Function | Description |
| - | - |
| `helpers.date.getYear()` | The current year |
| `helpers.date.formatDateTime(dateString, locale)` | Formats a date and time. `locale` defaults to `en-US` |
| `helpers.price.format(price, currency, locale)` | Formats a currency amount |

```njk theme={null}
<p>Total: {{ helpers.price.format(invoice.price, invoice.currency, 'en-US') }}</p>
<p>Placed {{ helpers.date.formatDateTime(invoice.created_at) }}</p>
```

Standard Nunjucks filters are available. See [Nunjucks](/developers/nunjucks) for the language itself.

## Writing a template

Content that came from you or the buyer is escaped by default, so fields holding HTML need `| safe`:

```njk theme={null}
{{ item.instructions | safe }}
```

Loops work as they do in themes:

```njk theme={null}
{% for item in invoice.items %}
  <p>{{ item.name }}: {{ item.quantity }} × {{ helpers.price.format(item.price, invoice.currency) }}</p>
{% endfor %}
```

Guard optional values. A template that assumes one will render badly when it is missing:

```njk theme={null}
{% if invoice.tracking_code %}
  <p>Tracking: {{ invoice.tracking_code }}</p>
{% endif %}
```

## Reverting

Deleting your version of a template restores the SellAuth default, including any improvements shipped since you overrode it. Useful for templates you customised once and no longer maintain.

## Next steps

<CardGroup cols={2}>
  <Card title="Email settings" icon="at" href="/guides/email-settings">
    Sending these emails from your own domain.
  </Card>

  <Card title="Nunjucks" icon="code" href="/developers/nunjucks">
    The template language reference.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.