Skip to content
Local Development

自定义电子邮件模板

Customize local email templates via the config file.

你可以通过编辑 config.toml 文件来自定义本地开发的邮件模板。

🌐 You can customize the email templates for local development by editing the config.toml file.

本指南涵盖本地开发和 CLI 工作流程。对于托管项目,请使用仪表板中的 Email Templates 页面。有关术语、限制和每个环境下适用的自定义模式,请参阅 Email templates

🌐 This guide covers local development and CLI workflows. For hosted projects, use the Email Templates page in the dashboard. See Email templates for terminology, limitations, and customization patterns that apply in every environment.

配置模板 #

🌐 Configuring templates

你应该为 content_path 参数提供一个相对 URL,指向包含模板的 HTML 文件。例如:

🌐 You should provide a relative URL to the content_path parameter, pointing to an HTML file which contains the template. For example:

认证邮件模板 #

🌐 Authentication email templates

1
[auth.email.template.invite]
2
subject = "You are invited to Acme Inc"
3
content_path = "./supabase/templates/invite.html"

安全通知邮件模板 #

🌐 Security notification email templates

1
[auth.email.notification.password_changed]
2
enabled = true
3
subject = "Your password was changed"
4
content_path = "./templates/password_changed_notification.html"

可用的身份验证邮件模板 #

🌐 Available authentication email templates

有几种与身份验证相关的电子邮件模板可以配置。每个模板都对应特定的身份验证流程:

🌐 There are several authentication-related email templates which can be configured. Each template serves a specific authentication flow:

auth.email.template.invite#

默认主题:"你已被邀请"
发送时间:当用户通过电子邮件邀请加入你的应用时
目的:邀请某人创建账户
内容:包含一个链接,供被邀请的用户接受邀请并创建他们的账户

auth.email.template.confirmation#

默认主题:"确认你的邮箱地址" 发送时间:用户注册并需要验证其邮箱地址时 目的:在用户注册后,请他们确认邮箱地址 内容:包含一个确认链接,用于验证用户的邮箱地址

auth.email.template.recovery#

默认主题:"重置你的密码" 发送时间:当用户请求重置密码时 目的:发送密码重置链接或验证码 内容:包含用于重置用户密码的链接

默认主题:"你的登录链接" 发送时间:当用户请求无密码认证的魔法链接或邮箱一次性密码时 目的:发送一次性登录链接或一次性密码 内容:包含一个安全链接,点击后可自动登录

auth.email.template.email_change#

默认主题: “确认你的新电子邮件地址” 发送时间: 当用户请求更改电子邮件地址时 目的: 在用户更改电子邮件地址后,请他们验证新邮箱 内容: 包含用于验证新电子邮件地址的确认链接

auth.email.template.reauthentication#

默认主语:“{{ .Token }} is your verification code发送时:当用户需要重新认证以进行敏感操作时 目的:要求用户在敏感操作前验证身份 内容:包含8位数的一次性密码验证码

可用的安全通知邮件模板 #

🌐 Available security notification email templates

有几种可以配置的安全通知邮件模板。只有在项目级别启用了相应的安全通知时,这些邮件才会发送给用户:

🌐 There are several security notification email templates which can be configured. These emails are only sent to users if the respective security notifications have been enabled at the project-level:

auth.email.notification.password_changed#

默认主题:"你的密码已更改" 发送时间:当用户的密码被更改时 用途:在密码更改时通知用户 内容:确认账户的密码已被更改

auth.email.notification.email_changed#

默认主题:“你的电子邮箱地址已更改” 发送时间:当用户的电子邮箱地址被更改时 用途:在用户的电子邮箱地址更改时通知用户 内容:确认电子邮箱地址已从旧地址更改为新地址

auth.email.notification.phone_changed#

默认主题: “你的电话号码已更改” 发送时间: 当用户的电话号码被更改时 目的: 当用户的电话号码更改时通知他们 内容: 确认从旧电话号码到新电话号码的更改

auth.email.notification.mfa_factor_enrolled#

默认主题:"你的账户已添加新的验证方法" 发送时间:当用户账户添加新的验证方法时 目的:在账户添加多因素验证方法时通知用户 内容:确认已添加新的验证方法

auth.email.notification.mfa_factor_unenrolled#

默认主题:"你的账户已移除一种验证方法" 发送时间:当用户账户中的验证方法被移除时 目的:在账户中的多因素验证方法被移除时通知用户 内容:确认已移除一种验证方法

auth.email.notification.identity_linked#

默认主题:"你的账户已关联一个登录方式" 发送时间:当一个登录方式被关联到账户时 目的:在登录方式被关联到账户时通知用户 内容:确认一个登录方式已被关联

auth.email.notification.identity_unlinked#

默认主题:"你的账户中已移除一种登录方式" 发送时间:当账户中的一种登录方式被移除时 目的:在登录方式被移除时通知用户 内容:确认一种登录方式已被移除

模板变量 #

🌐 Template variables

模板系统提供以下变量可供使用:

🌐 The templating system provides the following variables for use:

ConfirmationURL#

包含确认网址。例如,注册确认的网址看起来会像这样:

🌐 Contains the confirmation URL. For example, a signup confirmation URL would look like:

1
https://project-ref.supabase.co/auth/v1/verify?token={{ .TokenHash }}&type=email&redirect_to=https://example.com/path

用法

1
<p><a href="{{ .ConfirmationURL }}">Confirm email address</a></p>

Token#

包含一个8位数的一次性密码(OTP),可以用来代替 ConfirmationURL

🌐 Contains a 8-digit One-Time-Password (OTP) that can be used instead of the ConfirmationURL.

用法

1
<p>Here is your one time password: {{ .Token }}</p>

TokenHash#

包含 Token 的哈希版本。这在你自己在邮件模板中构建邮箱链接时很有用。

🌐 Contains a hashed version of the Token. This is useful for constructing your own email link in the email template.

用法

1
<p>Follow the link below to confirm this email address and finish signing up.</p>
2
<p>
3
<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email"
4
>Confirm email address</a
5
>
6
</p>

SiteURL#

包含你应用的网站 URL。你可以在项目的身份验证设置中进行配置。

🌐 Contains your application's Site URL. This can be configured in your project's authentication settings.

用法

1
<p>Visit <a href="{{ .SiteURL }}">here</a> to log in.</p>

RedirectTo#

包含作为身份验证方法调用中 redirectTo 选项传递的重定向 URL。

🌐 Contains the redirect URL passed as the redirectTo option in the auth method call.

用法

1
<a href="{{ .SiteURL }}/auth/confirm?token_hash={{ .TokenHash }}&type=email&next={{ .RedirectTo }}">
2
Confirm your email
3
</a>

Data#

包含来自 auth.users.user_metadata 的元数据。可以用它来个性化邮件信息。

🌐 Contains metadata from auth.users.user_metadata. Use this to personalize the email message.

用法

1
<p>Hello {{ .Data.first_name }}, please confirm your signup.</p>

Email#

包含用户的邮箱地址。

🌐 Contains the user's email address.

用法

1
<p>A recovery request was sent to {{ .Email }}.</p>

NewEmail#

包含新用户的电子邮件地址。这只在 email_change 邮件模板中可用。

🌐 Contains the new user's email address. This is only available in the email_change email template.

用法

1
<p>You are requesting to update your email address to {{ .NewEmail }}.</p>

OldEmail#

包含用户的旧邮箱地址。这个只在 email_changed_notification 邮件模板里有。

🌐 Contains the user's old email address. This is only available in the email_changed_notification email template.

用法

1
<p>The email address for your account has been changed from {{ .OldEmail }} to {{ .Email }}.</p>

Phone#

包含用户的新电话号码。这个信息只在 phone_changed_notification 邮件模板中可用。

🌐 Contains the user's new phone number. This is only available in the phone_changed_notification email template.

用法

1
<p>The phone number for your account has been changed from {{ .OldPhone }} to {{ .Phone }}.</p>

OldPhone#

包含用户的旧电话号码。这只在 phone_changed_notification 邮件模板中可用。

🌐 Contains the user's old phone number. This is only available in the phone_changed_notification email template.

用法

1
<p>The phone number for your account has been changed from {{ .OldPhone }} to {{ .Phone }}.</p>

Provider#

包含已关联或已移除的登录方法提供者。此信息仅在 identity_linked_notificationidentity_unlinked_notification 邮件模板中可用。

🌐 Contains the provider of the linked or removed sign-in method. This is only available in the identity_linked_notification and identity_unlinked_notification email templates.

用法

1
<p>Your {{ .Provider }} account was linked as a sign-in method.</p>

FactorType#

包含已添加或删除的验证方法类型。这个只在 mfa_factor_enrolled_notificationmfa_factor_unenrolled_notification 邮件模板中可用。

🌐 Contains the type of verification method that was added or removed. This is only available in the mfa_factor_enrolled_notification and mfa_factor_unenrolled_notification email templates.

用法

1
<p>Sign-in verification method {{ .FactorType }} was added to your account.</p>

部署电子邮件模板 #

🌐 Deploying email templates

这些设置是用于本地开发的。要在本地应用更改,请停止并重启 Supabase 容器:

🌐 These settings are for local development. To apply the changes locally, stop and restart the Supabase containers:

1
supabase stop && supabase start

对于由 Supabase 托管的项目,将模板复制到仪表板的邮件模板部分。

🌐 For hosted projects managed by Supabase, copy the templates into the Email Templates section of the Dashboard.