App Logo
Reference

Email Templates

Authula uses Go's html/template and text/template engines for all email rendering. Templates are embedded at build time via go:embed, with optional runtime overrides via environment variables.

Architecture

Every email type (verify email, password reset, magic link sign-in, etc.) has three template files under its plugin's templates/ directory:

FileEnginePurpose
subject.tmpltext/templateEmail subject line
text.tmpltext/templatePlain-text body
html.tmplhtml/templateHTML body (auto-escaped, missingkey=error)

Templates are parsed eagerly during plugin Init(). If parsing fails, the plugin fails to start (fail-fast). Environment variable overrides are read once at startup and are immutable for the process lifetime.

Available template functions

FunctionSignatureDescription
humanDurationhumanDuration .ExpiryFormats a time.Duration as e.g. "1 hour", "24 hours", "2 days"
pluralplural "item" .CountReturns singular or plural form
upperupper .StringUppercases the string
lowerlower .StringLowercases the string
titletitle .StringTitle-cases the first character
currentYearcurrentYearReturns the current year (e.g. 2026)

Context structs

Each template receives a context struct that embeds CommonContext:

CommonContext:

  • AppName — the application name (from config)
  • BaseURL — the base URL of the API

Email Types & Contexts

1. Email/Password Plugin

Verify Email

FieldTypeDescription
UserEmailstringRecipient's email
VerificationLinkstringOne-click verification URL
Expirytime.DurationLink expiration duration

Password Reset

FieldTypeDescription
UserEmailstringRecipient's email
ResetLinkstringPassword reset URL
Expirytime.DurationLink expiration duration

Password Changed

FieldTypeDescription
UserEmailstringRecipient's email

Email Change Request

FieldTypeDescription
UserEmailstringCurrent email
OldEmailstringOld email address
NewEmailstringNew email address
ChangeLinkstringEmail change confirmation URL
Expirytime.DurationLink expiration duration

Email Changed

FieldTypeDescription
UserEmailstringRecipient's email (varies per recipient)
OldEmailstringOld email address
NewEmailstringNew email address

This template is rendered twice: once for the old address (UserEmail = old) and once for the new address (UserEmail = new).


FieldTypeDescription
UserEmailstringUser's email
MagicLinkstringOne-click sign-in URL
Expirytime.DurationLink expiration duration

3. Organizations Plugin

Organization Invitation

FieldTypeDescription
InvitationEmailstringInvitee's email
OrganizationNamestringOrganization name
RolestringAssigned role
AcceptLinkstringInvitation acceptance URL
Expirytime.DurationInvitation expiration duration

Overriding Templates via Environment Variables

Every email template can be overridden at startup using environment variables. The naming convention is:

AUTHULA_TEMPLATE_<EMAIL_TYPE>_SUBJECT
AUTHULA_TEMPLATE_<EMAIL_TYPE>_TEXT
AUTHULA_TEMPLATE_<EMAIL_TYPE>_HTML

Where <EMAIL_TYPE> is the uppercase, underscore-separated email type name.

Email/Password Plugin

Env VariableOverrides
AUTHULA_TEMPLATE_VERIFY_EMAIL_SUBJECTVerify email subject
AUTHULA_TEMPLATE_VERIFY_EMAIL_TEXTVerify email plain text
AUTHULA_TEMPLATE_VERIFY_EMAIL_HTMLVerify email HTML
AUTHULA_TEMPLATE_PASSWORD_RESET_REQUEST_SUBJECTPassword reset request subject
AUTHULA_TEMPLATE_PASSWORD_RESET_REQUEST_TEXTPassword reset request plain text
AUTHULA_TEMPLATE_PASSWORD_RESET_REQUEST_HTMLPassword reset request HTML
AUTHULA_TEMPLATE_PASSWORD_CHANGED_SUBJECTPassword changed subject
AUTHULA_TEMPLATE_PASSWORD_CHANGED_TEXTPassword changed plain text
AUTHULA_TEMPLATE_PASSWORD_CHANGED_HTMLPassword changed HTML
AUTHULA_TEMPLATE_EMAIL_CHANGE_REQUEST_SUBJECTEmail change request subject
AUTHULA_TEMPLATE_EMAIL_CHANGE_REQUEST_TEXTEmail change request plain text
AUTHULA_TEMPLATE_EMAIL_CHANGE_REQUEST_HTMLEmail change request HTML
AUTHULA_TEMPLATE_EMAIL_CHANGED_SUBJECTEmail changed subject
AUTHULA_TEMPLATE_EMAIL_CHANGED_TEXTEmail changed plain text
AUTHULA_TEMPLATE_EMAIL_CHANGED_HTMLEmail changed HTML
Env VariableOverrides
AUTHULA_TEMPLATE_MAGIC_LINK_SIGN_IN_SUBJECTMagic link subject
AUTHULA_TEMPLATE_MAGIC_LINK_SIGN_IN_TEXTMagic link plain text
AUTHULA_TEMPLATE_MAGIC_LINK_SIGN_IN_HTMLMagic link HTML

Organizations Plugin

Env VariableOverrides
AUTHULA_TEMPLATE_ORGANIZATION_INVITATION_SUBJECTOrg invitation subject
AUTHULA_TEMPLATE_ORGANIZATION_INVITATION_TEXTOrg invitation plain text
AUTHULA_TEMPLATE_ORGANIZATION_INVITATION_HTMLOrg invitation HTML

Example: Override the verify email HTML template

# .env
AUTHULA_TEMPLATE_VERIFY_EMAIL_HTML="<div>
  <h1>Hi {{.UserEmail}},</h1>
  <p>Click <a href='{{.VerificationLink}}'>here</a> to verify your email.</p>
  <p>This link expires in {{humanDuration .Expiry}}.</p>
</div>"

Viewing Default Templates

The built-in templates are embedded in each plugin's templates/ directory:

plugins/email-password/templates/*
plugins/magic-link/templates/*
plugins/organizations/templates/*

Template Syntax

Templates use Go's standard template syntax ({{.FieldName}}). The HTML templates automatically escape HTML characters (e.g., < becomes &lt;), so you never need to manually escape values in the HTML body.

subject.tmpl example

Verify your email

text.tmpl example

Verify your email by clicking the following link: {{.VerificationLink}}.

html.tmpl example

<div>
  <p>Hello {{.UserEmail}},</p>
  <p>
    Please verify your email address by clicking the following link:
    <a href="{{.VerificationLink}}">Verify your email</a>
  </p>
  <p>This link will expire in {{humanDuration .Expiry}}.</p>
  <p>If you did not request this, please ignore this email.</p>
</div>

On this page