# Email templates (Mailgun)

The backend sends transactional email through Mailgun **templates**: it passes the template name and its variables
(`src/utils/mailer.ts`), and Mailgun renders the HTML. These files are the source of those templates. After changing
one, upload it to Mailgun again.

| File | Mailgun template name (env) | Subject sent by the backend | Variables |
| --- | --- | --- | --- |
| `invite.html` | `blenaxis-invite` (`MAILGUN_TEMPLATE_INVITE`) | "{invitedByName} invited you to {organizationName} on BlenAxis" | `name`, `organizationName`, `invitedByName`, `inviteUrl`, `expiresAt`, `roles`, `isOrganizationAdmin`, `supportEmail` |
| `password-reset.html` | `blenaxis-password-reset` (`MAILGUN_TEMPLATE_PASSWORD_RESET`) | "Reset your BlenAxis password" | `name`, `organizationName`, `resetUrl`, `supportEmail` |
| `access-request.html` | `blenaxis-access-request` (`MAILGUN_TEMPLATE_ACCESS_REQUEST`) | "{requesterName} is asking for access to {what}" | `adminName`, `requesterName`, `requesterEmail`, `requesterRoles`, `what`, `pageUrl`, `usersUrl`, `message`, `organizationName` |
| `organization-admin-invite.html` | `blenaxis-organization-admin-invite` (`MAILGUN_TEMPLATE_ORGANIZATION_ADMIN_INVITE`) | "Activate {organizationName} on BlenAxis" | `name`, `organizationName`, `inviteUrl`, `expiresAt`, `supportEmail` |

## Uploading to Mailgun

1. Mailgun dashboard → **Send** → **Templates** (for your sending domain) → **Create message template**.
2. Name it exactly as in the table (or set the env variable to your name), choose the HTML editor, paste the file's
   contents and save. The `{{variable}}` placeholders are Mailgun's Handlebars syntax.
3. In the backend `.env`, set `MAILGUN_API_KEY`, `MAILGUN_DOMAIN`, `MAILGUN_REGION` (`us` or `eu`, matching your domain)
   and optionally `MAIL_FROM` (defaults to `BlenAxis <no-reply@MAILGUN_DOMAIN>`), then restart the backend.

Without `MAILGUN_API_KEY` / `MAILGUN_DOMAIN`, nothing is sent: in development the backend logs the email and its link
instead, so invites can still be tested (admins can also copy an invite link from the Users screen).

The logo is linked directly in each template: the public S3 copy at
`https://blenaxis-public-assets.s3.ap-south-1.amazonaws.com/brand/blenaxis-logo-email.png`. To change the logo, replace
that file (`npm run storage:upload-brand` uploads `assets/brand/blenaxis-logo-email.png`); the templates stay as they are.

Colours are the BlenAxis design tokens written as hex, because email clients don't support CSS variables.
