电子邮件
电子邮件功能使 Strapi 应用能够从服务器或外部提供商发送电子邮件。
¥The Email feature enables Strapi applications to send emails from a server or an external provider.
配置
¥Configuration
电子邮件功能的大多数配置选项都通过你的 Strapi 项目的代码处理。电子邮件功能无法在管理面板中配置,但是如果管理员已设置电子邮件,用户可以测试电子邮件传递。
¥Most configuration options for the Email feature are handled via your Strapi project's code. The Email feature is not configurable in the admin panel, however users can test email delivery if it has been setup by an administrator.
管理面板设置
¥Admin panel settings
配置功能的路径: 设置 > 电子邮件功能 > 配置
¥Path to configure the feature: Settings > Email feature > Configuration


在配置界面中,只有 "测试电子邮件传递" 下的电子邮件地址字段可供用户修改。发送测试电子邮件按钮可发送测试电子邮件。
¥In the Configuration interface, only the email address field under "Test email delivery" is modifiable by users. A Send test email button sends a test email.
此页面仅在当前角色启用了 "访问电子邮件设置页面" 权限时可见(有关更多信息,请参阅 RBAC 功能 文档):
¥This page is only visible if the current role has the "Access the Email Settings page" permission enabled (see RBAC feature documentation for more information):


基于代码的配置
¥Code-based configuration
电子邮件功能需要提供程序以及 config/plugins.js|ts
文件中的提供程序配置。有关详细的安装和配置说明,请参阅 providers。
¥The Email feature requires a provider and a provider configuration in the config/plugins.js|ts
file. See providers for detailed installation and configuration instructions.
发送邮件 是 Strapi 电子邮件功能中的默认电子邮件提供商。它为本地开发环境提供功能,但在默认配置中不适合生产。对于生产阶段应用,你需要进一步配置 Sendmail
或更改提供商。
¥Sendmail is the default email provider in the Strapi Email feature. It provides functionality for the local development environment but is not production-ready in the default configuration. For production stage applications you need to further configure Sendmail
or change providers.
电子邮件配置选项
¥Email configuration options
插件配置在 config/plugins.js
文件或 config/plugins.ts
文件中定义。请参阅 providers,了解特定于提供商的详细安装和配置说明。
¥Plugins configuration are defined in the config/plugins.js
file or config/plugins.ts
file. Please refer to providers for detailed provider-specific installation and configuration instructions.
选项 | 类型 | 描述 | 默认值 | 注意 |
---|---|---|---|---|
provider | string | 要使用的电子邮件提供商。 | sendmail | 必需的 |
providerOptions | object | 电子邮件提供商选项。 | {} | 可选的 |
providerOptions.apiKey | string | 电子邮件提供商的 API 密钥。 | '' | 可选的 |
settings | object | 电子邮件设置。 | {} | 可选的 |
settings.defaultFrom | string | 用作发件人的默认电子邮件地址。 | '' | 可选的 |
settings.defaultReplyTo | string | 用作回复地址的默认电子邮件地址。 | '' | 可选的 |
ratelimit | object | 电子邮件速率限制设置。 | {} | 可选的 |
ratelimit.enabled | boolean | 是否启用速率限制。 | true | 可选的 |
ratelimit.interval | string | 速率限制的间隔(分钟)。 | 5 | 可选的 |
ratelimit.max | number | 间隔内允许的最大请求数。 | 5 | 可选的 |
ratelimit.delayAfter | number | 应用速率限制之前允许的请求数。 | 1 | 可选的 |
ratelimit.timeWait | number | 响应请求之前等待的时间(以毫秒为单位)。 | 1 | 可选的 |
ratelimit.prefixKey | string | 速率限制键的前缀。 | ${userEmail} | 可选的 |
ratelimit.whitelist | array(string) | 要从速率限制中列入白名单的 IP 地址数组。 | [] | 可选的 |
ratelimit.store | object | 速率限制存储位置,有关更多信息,请参阅 koa2-ratelimit 文档。 | MemoryStore | 可选的 |
提供者
¥Providers
电子邮件功能可以通过安装和配置其他提供程序来扩展。
¥The Email feature can be extended via the installation and configuration of additional providers.
提供商为插件的核心功能添加了扩展,例如,使用 Amazon SES 而不是 Sendmail 来发送电子邮件。
¥Providers add an extension to the core capabilities of the plugin, for example to use Amazon SES for emails instead of Sendmail.
Strapi 维护的官方提供程序(可通过 市场 找到)以及许多社区维护的提供程序(可通过 npm 获取)。
¥There are both official providers maintained by Strapi — discoverable via the Marketplace — and many community maintained providers available via npm.
可以将提供程序配置为 private,以确保对资源 URL 进行签名以实现安全访问。
¥A provider can be configured to be private to ensure asset URLs will be signed for secure access.
安装提供程序
¥Installing providers
可以使用 npm
或 yarn
使用以下格式 @strapi/provider-<plugin>-<provider> --save
安装新的提供程序。