Skip to content

Updated

Email templates

Customize the authentication and security notification emails Supabase Auth sends.

Supabase Auth sends two kinds of email: authentication emails and security notifications.

Authentication emails:

  • Confirm sign up
  • Invite user
  • Magic link or OTP
  • Change email address
  • Reset password
  • Reauthentication

Security notification emails:

  • Password changed
  • Email address changed
  • Phone number changed
  • Sign-in method linked
  • Sign-in method removed
  • Verification method added
  • Verification method removed

Supabase Auth sends a security notification only when that notification is turned on for the project.

The confirmation email is sent only when email confirmations are on. In a hosted project, turn on Confirm email on the Auth Providers page, or set mailer_autoconfirm to false with the Management API. In local development, set auth.email.enable_confirmations to true in your config file, then restart the local stack. With confirmations off, users are confirmed on sign-up and no email is sent, so a customized confirmation template never reaches them.

Template variables

Templates can use the following variables:

NameDescription
{{ .ConfirmationURL }}Contains the confirmation URL. For example, a sign-up confirmation URL looks like: https://project-ref.supabase.co/auth/v1/verify?token={{ .TokenHash }}&type=email&redirect_to=https://example.com/path.
{{ .Token }}Contains a 6-digit one-time password (OTP) to use instead of the {{ .ConfirmationURL }}.
{{ .TokenHash }}Contains a hashed version of the {{ .Token }}. Use it to build your own link in the email template.
{{ .SiteURL }}Contains your application's Site URL. Configure it in your project's authentication settings.
{{ .RedirectTo }}Contains the redirect URL passed when signUp, signInWithOtp, signInWithOAuth, resetPasswordForEmail, or inviteUserByEmail is called. Configure the redirect URL allow list in your project's authentication settings.
{{ .Data }}Contains metadata from auth.users.user_metadata. Use this to personalize the email message.
{{ .Email }}Contains the original email address of the user. Empty when you link an email address to an anonymous user.
{{ .NewEmail }}Contains the new email address of the user. This variable is only supported in the "Change email address" template.
{{ .OldEmail }}Contains the old email address of the user. This variable is only supported in the "Email address changed notification" template.
{{ .Phone }}Contains the new phone number of the user. This variable is only supported in the "Phone number changed notification" template.
{{ .OldPhone }}Contains the old phone number of the user. This variable is only supported in the "Phone number changed notification" template.
{{ .Provider }}Contains the provider of the linked or removed sign-in method. This variable is only supported in the "Sign-in method linked" and "Sign-in method removed" notification templates.
{{ .FactorType }}Contains the type of verification method that was added or removed. This variable is only supported in the "Verification method added" and "Verification method removed" notification templates.

Editing email templates

Where you edit templates depends on how you run Supabase.

Hosted projects

Edit templates on the Email Templates page in the dashboard. The template builder uses the same template variables.

You can also manage email templates using the Management API:

# Get your access token from https://supabase.com/dashboard/account/tokens
export SUPABASE_ACCESS_TOKEN="your-access-token"
export PROJECT_REF="your-project-ref"
# Get current email templates
curl -X GET "https://api.supabase.com/v1/projects/$PROJECT_REF/config/auth" \
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \
| jq 'to_entries | map(select(.key | startswith("mailer_templates"))) | from_entries'
# Update email templates
curl -X PATCH "https://api.supabase.com/v1/projects/$PROJECT_REF/config/auth" \
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"mailer_subjects_confirmation": "Confirm your email address",
"mailer_templates_confirmation_content": "<h2>Confirm your email address</h2><p>Follow the link below to confirm this email address and finish signing up.</p><p><a href=\"{{ .ConfirmationURL }}\">Confirm email address</a></p>",
"mailer_subjects_magic_link": "Your sign-in link",
"mailer_templates_magic_link_content": "<h2>Your sign-in link</h2><p>Follow the link below to sign in. This link expires shortly and can only be used once.</p><p><a href=\"{{ .ConfirmationURL }}\">Sign in</a></p>",
"mailer_subjects_recovery": "Reset your password",
"mailer_templates_recovery_content": "<h2>Reset your password</h2><p>We received a request to reset your password. Follow the link below to choose a new one.</p><p><a href=\"{{ .ConfirmationURL }}\">Reset password</a></p><p>If you didn't request this, you can safely ignore this email.</p>",
"mailer_subjects_invite": "You've been invited",
"mailer_templates_invite_content": "<h2>You've been invited</h2><p>You've been invited to create an account. Follow the link below to accept.</p><p><a href=\"{{ .ConfirmationURL }}\">Accept invitation</a></p>",
"mailer_subjects_reauthentication": "{{ .Token }} is your verification code",
"mailer_templates_reauthentication_content": "<h2>Your verification code</h2><p>Use the code below to verify your identity. It expires shortly.</p><p>{{ .Token }}</p>",
"mailer_subjects_email_change": "Confirm your new email address",
"mailer_templates_email_change_content": "<h2>Confirm your new email address</h2><p>Follow the link below to confirm {{ .NewEmail }} as your new email address.</p><p><a href=\"{{ .ConfirmationURL }}\">Confirm new email address</a></p><p>If you didn't request this change, you can safely ignore this email.</p>",
"mailer_notifications_password_changed_enabled": true,
"mailer_subjects_password_changed_notification": "Your password was changed",
"mailer_templates_password_changed_notification_content": "<h2>Your password was changed</h2>\n\n<p>The password for your account was recently changed.</p>\n<p>If you didn't make this change, reset your password and contact support immediately.</p>",
"mailer_notifications_email_changed_enabled": true,
"mailer_subjects_email_changed_notification": "Your email address was changed",
"mailer_templates_email_changed_notification_content": "<h2>Your email address was changed</h2>\n\n<p>The email address for your account was changed from {{ .OldEmail }} to {{ .Email }}.</p>\n<p>If you didn't make this change, contact support immediately.</p>",
"mailer_notifications_phone_changed_enabled": true,
"mailer_subjects_phone_changed_notification": "Your phone number was changed",
"mailer_templates_phone_changed_notification_content": "<h2>Your phone number was changed</h2>\n\n<p>The phone number for your account was changed from {{ .OldPhone }} to {{ .Phone }}.</p>\n<p>If you didn't make this change, contact support immediately.</p>",
"mailer_notifications_mfa_factor_enrolled_enabled": true,
"mailer_subjects_mfa_factor_enrolled_notification": "A new verification method was added to your account",
"mailer_templates_mfa_factor_enrolled_notification_content": "<h2>A new verification method was added</h2>\n\n<p>Sign-in verification method {{ .FactorType }} was added to your account.</p>\n<p>If you didn't make this change, contact support immediately.</p>",
"mailer_notifications_mfa_factor_unenrolled_enabled": true,
"mailer_subjects_mfa_factor_unenrolled_notification": "A verification method was removed from your account",
"mailer_templates_mfa_factor_unenrolled_notification_content": "<h2>A verification method was removed</h2>\n\n<p>Sign-in verification method {{ .FactorType }} was removed from your account.</p>\n<p>If you didn't make this change, contact support immediately.</p>",
"mailer_notifications_identity_linked_enabled": true,
"mailer_subjects_identity_linked_notification": "A sign-in method was linked to your account",
"mailer_templates_identity_linked_notification_content": "<h2>A sign-in method was linked</h2>\n\n<p>Your {{ .Provider }} account was linked as a sign-in method for {{ .Email }}.</p>\n<p>If you didn't make this change, contact support immediately.</p>",
"mailer_notifications_identity_unlinked_enabled": true,
"mailer_subjects_identity_unlinked_notification": "A sign-in method was removed from your account",
"mailer_templates_identity_unlinked_notification_content": "<h2>A sign-in method was removed</h2>\n\n<p>Your {{ .Provider }} account was removed as a sign-in method for {{ .Email }}.</p>\n<p>If you didn't make this change, contact support immediately.</p>"
}'

Local development and self-hosted

The dashboard template builder doesn't apply to local development with the CLI or self-hosted Supabase. With the CLI, customize templates in your config file (supabase/config.toml or supabase/config.jsonc) and in local HTML files. Self-hosted Supabase uses environment variables instead.

For local development with the CLI, open the emails your templates produce in Mailpit.

Customization

Supabase Auth uses Go templates, so you can render content conditionally based on template variables.

Send different email to early access users

Send a different email to users who signed up through an early access domain (https://www.earlyaccess.trial.com).

{{ if eq .Data.Domain "https://www.example.com" }}
<h1>Welcome to Our Database Service!</h1>
<p>Dear Developer,</p>
<p>Welcome to Billy, the scalable developer platform!</p>
<p>Best Regards,<br>
Billy Team</p>
{{ else if eq .Data.Domain "https://www.earlyaccess.trial.com" }}
<h1>Welcome to Our Database Service!</h1>
<p>Dear Developer,</p>
<p>Welcome Billy, the scalable developer platform!</p>
<p> As an early access member, you have access to select features like Point To Space Restoration.</p>
<p>Best Regards,<br>
Billy Team</p>
{{ end }}

Limitations

Email prefetching

Some email providers scan incoming email for spam or other threats and open the links in it, for example Safe Links in Microsoft Defender for Office 365. The scan uses up the {{ .ConfirmationURL }} link, so the user gets a "Token has expired or is invalid" error when they open it.

To avoid this, use one of the following approaches.

Send an OTP instead of a link

  1. Include {{ .Token }} in the email template.

  2. Link to a page in your app where the user enters their email address and the OTP:

    <a href="{{ .SiteURL }}/confirm-signup">Confirm email address</a>
  3. Sign the user in by verifying the OTP with supabase.auth.verifyOtp:

    const { , } = await ..({ , , : 'email' })

Confirm with a button on your own page

  1. Link to a page in your app and pass the confirmation URL as a query parameter:

    <a href="{{ .SiteURL }}/confirm-signup?confirmation_url={{ .ConfirmationURL }}">
    Confirm email address
    </a>
  2. On that page, read the confirmation_url query parameter and use it as the target of a button. The user confirms by clicking the button.

Email tracking

Email tracking in an external email provider rewrites the links in Supabase email templates, and the rewritten links don't work. Turn off email tracking in your provider.

Redirecting the user to a server-side endpoint

With server-side rendering, you might want the email link to go to a server-side endpoint that checks whether the user is authenticated before it returns the page. The default email link redirects the user after verification with the session in the URL fragment. The server never receives the fragment, so it can't read the session.

Instead, point the link in the email template at your server-side endpoint. For example:

<a
href="https://api.example.com/v1/authenticate?token_hash={{ .TokenHash }}&type=invite&redirect_to={{ .RedirectTo }}"
>
Accept the invite
</a>

When the user clicks the link, the request goes to https://api.example.com/v1/authenticate. Read the token_hash, type, and redirect_to query parameters from the URL, then call verifyOtp to get a session. verifyOtp sends a POST request to Supabase Auth, so the session comes back in the response body, where the server can read it. Then redirect the user to redirect_to. For example:

const { , } = .(new (.).)
const {
: { },
,
} = await ..({ , : as })
// subsequently redirect the user back to the client using the redirect_to param
// ...

Mobile deep linking

To send users from an email link to a specific page in a mobile app, see Native mobile deep linking.