电子邮件提供商
电子邮件提供商负责发送 Casdoor 的邮件,例如注册和登录时的验证码、密码重置链接以及通知。本页介绍 SMTP 提供商的设置和电子邮件模板。本节的其他页面涵盖特定服务。
添加 SMTP 提供商
-
在 Casdoor 管理控制台中,转到 Identity > Providers 并添加一个提供商。
-
将 Category 设置为
Email,将 Type 设置为Default(通过 SMTP 发送)。 -
输入 SMTP 服务器的 Host、Port、Username 和 Password,以及 From address。

-
编写 Email title 和 Email content。请参阅 Templates。

-
点击 Test SMTP Connection 检查连接,点击 Send Testing Email 向 Test Email 地址发送消息。
-
保存提供商并将其添加到你的应用。请参阅 Add providers to an application。
其他电子邮件类型
| Type | Sends through |
|---|---|
Default | An SMTP server, as described on this page |
SUBMAIL, Mailtrap | The SMTP server of the service, with the same fields as Default |
Azure ACS | Azure Communication Services. See Azure ACS |
SendGrid | SendGrid. See SendGrid |
Resend | Resend. See Resend |
Microsoft 365 | Exchange Online 的 SMTP 服务器,使用 OAuth 而非密码登录。参见 Microsoft 365 |
Microsoft Graph | Microsoft Graph 的 sendMail API,适用于关闭了 SMTP AUTH 的租户。请参阅 Microsoft Graph |
Gmail | Gmail 的 SMTP 服务器,使用 Google JSON 密钥而不是应用密码进行登录。请参阅 Gmail |
Custom HTTP Email | An HTTP API that you describe. See Send email through your own HTTP API |
SSL 模式
SSL mode 控制 Casdoor 如何与 SMTP 服务器协商 TLS:
| 值 | 行为 |
|---|---|
Auto (default) | Decides by the port: implicit TLS on port 465, STARTTLS on other ports |
启用 | Always uses implicit TLS. Use it when the server requires implicit TLS on a non-standard port |
关闭 | Doesn't use TLS. Use it only for servers on a trusted internal network |
之前启用了 Disable SSL 选项的提供商行为等同于 Disable。你无需手动迁移它们。
代理
如果 Casdoor 无法直接访问 SMTP 服务器(例如从受限网络访问 Gmail),请启用 Enable proxy。Casdoor 随后会通过 conf/app.conf 中 socks5Proxy 设置的 SOCKS5 代理发送邮件。对于 SMTP,请将 socks5Proxy 写为 host:port:SMTP 连接不接受值中的 socks5:// 前缀或用户名和密码。
An email provider that belongs to an organization other than admin, built-in, and the trusted organizations can send only to SMTP servers and HTTP endpoints at Internet addresses. See Which addresses a provider can reach.
模板
Email title 和 Email content 可以包含以下占位符:
| 占位符 | Replaced by |
|---|---|
%{user.friendlyName} | The display name or another friendly name of the user |
%s | The verification code |
%link | The password reset URL. Use it only inside a <reset-link> block. In a magic-link email, the sign-in link |
%expireTime | 魔法链接的有效期(分钟)。仅在魔法链接邮件中替换 |
密码重置链接
要让用户通过邮件中的链接重置密码,请在 <reset-link> 块中放置链接文本和 %link。Casdoor 仅在密码重置邮件中显示该块,并从所有其他邮件(如注册和登录验证码)中移除它。
仅当 Casdoor 知道其自身的公共 URL 时才会填充 %link:即在 conf/app.conf 中设置了 origin 或 originFrontend,或者请求通过回环主机(如 localhost)到达 Casdoor。否则,Casdoor 也会从密码重置邮件中移除 <reset-link> 块,邮件中只包含代码。Casdoor 不会根据请求的 Host 标头构建链接,因为任何人都可以设置该标头。同样的规则适用于魔术链接,如果未正确配置,它将失败并提示 please set "origin" in conf/app.conf to send magic links。请参阅 Configuration reference。
魔法链接邮件使用相同的 Email content。如果内容中没有 %link,Casdoor 将发送包含链接的内置正文。
验证码和魔法链接的有效时间为 verificationCodeTimeout 分钟,设置在 conf/app.conf 中。默认为 10。以下示例说明为 10 分钟,如果您更改了设置,请相应修改文本。
纯文本:
You have requested a verification code at Casdoor. Here is your code: %s, please enter in 10 minutes. <reset-link>Or click %link to reset</reset-link>
HTML:
<!DOCTYPE html>
<html>
<body>
<h2>Password Reset Request</h2>
<p>Hello %{'{'}user.friendlyName{'}'},</p>
<p>Your verification code is: <strong>%s</strong></p>
<p>This code will expire in 10 minutes.</p>
<reset-link>
<p>Alternatively, you can <a href="%link">click here to reset your password</a> directly.</p>
</reset-link>
<p>If you didn't request this, please ignore this email.</p>
</body>
</html>
