Strapi Cloud 的电子邮件提供商配置
🌐 Email Providers configuration for Strapi Cloud
Page summary:
第三方电子邮件服务通过插件和环境变量集成,以替代默认发件人。
Strapi Cloud 开箱即用自带一个基础的电子邮件提供商。不过,如果需要,它也可以配置为使用其他电子邮件提供商。
🌐 Strapi Cloud comes with a basic email provider out of the box. However, it can also be configured to utilize another email provider, if needed.
请注意,Strapi 无法为第三方电子邮件提供商提供支持。
🌐 Please be advised that Strapi is unable to provide support for third-party email providers.
- 一个在
v4.8.2+上运行的本地 Strapi 项目。 - 另一个电子邮件提供商的凭据(请参见 Strapi Market)。
配置
🌐 Configuration
配置另一个电子邮件提供商以在 Strapi Cloud 中使用需要三个步骤:
🌐 Configuring another email provider for use with Strapi Cloud requires 3 steps:
- 在本地 Strapi 项目中安装提供程序插件。
- 在本地 Strapi 项目中配置提供者。
- 将环境变量添加到 Strapi Cloud 项目中。
安装提供程序插件
🌐 Install the Provider Plugin
使用 npm 或 yarn,按照对应供应商在 Marketplace 中的条目说明,将提供程序插件作为包依赖安装到本地 Strapi 项目中。
配置提供者
🌐 Configure the Provider
在你的 Strapi 项目中,创建一个 ./config/env/production/plugins.js 或 ./config/env/production/plugins.ts 文件,并包含以下内容:
🌐 In your Strapi project, create a ./config/env/production/plugins.js or ./config/env/production/plugins.ts file with the following content:
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
// … some unrelated plugins configuration options
email: {
config: {
// … provider-specific upload configuration options go here
}
// … some other unrelated plugins configuration options
}
});
export default ({ env }) => ({
// … some unrelated plugins configuration options
email: {
config: {
// … provider-specific upload configuration options go here
}
// … some other unrelated plugins configuration options
}
});
文件结构必须与上述路径完全匹配,否则配置将不会应用到 Strapi 云。
🌐 The file structure must match the above path exactly, or the configuration will not be applied to Strapi Cloud.
每个提供商将有不同的配置设置可用。请查看 Marketplace中该提供商的相应条目。
示例:
- JavaScript
- TypeScript
- Sendgrid
- Amazon SES
- Mailgun
module.exports = ({ env }) => ({
// ...
email: {
config: {
provider: 'sendgrid',
providerOptions: {
apiKey: env('SENDGRID_API_KEY'),
},
settings: {
defaultFrom: 'myemail@protonmail.com',
defaultReplyTo: 'myemail@protonmail.com',
},
},
},
// ...
});
module.exports = ({ env }) => ({
// ...
email: {
config: {
provider: 'amazon-ses',
providerOptions: {
key: env('AWS_SES_KEY'),
secret: env('AWS_SES_SECRET'),
amazon: 'https://email.us-east-1.amazonaws.com',
},
settings: {
defaultFrom: 'myemail@protonmail.com',
defaultReplyTo: 'myemail@protonmail.com',
},
},
},
// ...
});
module.exports = ({ env }) => ({
// ...
email: {
config: {
provider: 'mailgun',
providerOptions: {
key: env('MAILGUN_API_KEY'), // Required
domain: env('MAILGUN_DOMAIN'), // Required
url: env('MAILGUN_URL', 'https://api.mailgun.net'), //Optional. If domain region is Europe use 'https://api.eu.mailgun.net'
},
settings: {
defaultFrom: 'myemail@protonmail.com',
defaultReplyTo: 'myemail@protonmail.com',
},
},
},
// ...
});
- Sendgrid
- Amazon SES
- Mailgun
export default ({ env }) => ({
// ...
email: {
config: {
provider: 'sendgrid',
providerOptions: {
apiKey: env('SENDGRID_API_KEY'),
},
settings: {
defaultFrom: 'myemail@protonmail.com',
defaultReplyTo: 'myemail@protonmail.com',
},
},
},
// ...
});
export default ({ env }) => ({
// ...
email: {
config: {
provider: 'amazon-ses',
providerOptions: {
key: env('AWS_SES_KEY'),
secret: env('AWS_SES_SECRET'),
amazon: 'https://email.us-east-1.amazonaws.com',
},
settings: {
defaultFrom: 'myemail@protonmail.com',
defaultReplyTo: 'myemail@protonmail.com',
},
},
},
// ...
});
export default ({ env }) => ({
// ...
email: {
config: {
provider: 'mailgun',
providerOptions: {
key: env('MAILGUN_API_KEY'), // Required
domain: env('MAILGUN_DOMAIN'), // Required
url: env('MAILGUN_URL', 'https://api.mailgun.net'), //Optional. If domain region is Europe use 'https://api.eu.mailgun.net'
},
settings: {
defaultFrom: 'myemail@protonmail.com',
defaultReplyTo: 'myemail@protonmail.com',
},
},
},
// ...
});
在将上述更改推送到 GitHub 之前,向 Strapi Cloud 项目添加环境变量,以防在更改完成之前触发项目的重建和新部署。
🌐 Before pushing the above changes to GitHub, add environment variables to the Strapi Cloud project to prevent triggering a rebuild and new deployment of the project before the changes are complete.
Strapi 云配置
🌐 Strapi Cloud Configuration
- 登录 Strapi Cloud,然后在“项目”页面上点击相应的项目。
- 点击 设置 标签,然后在左侧菜单中选择 变量。
- 添加电子邮件提供商特定的所需环境变量。
- 点击 保存。
示例:
- SendGrid
- Amazon SES
- Mailgun
| 变量 | 值 ||--------------------|-----------------------|| SENDGRID_API_KEY | your_sendgrid_api_key |
| 变量 | 值 ||------------------|---------------------|| AWS_SES_KEY | your_aws_ses_key || AWS_SES_SECRET | your_aws_ses_secret |
| 变量 | 值 ||-------------------|----------------------|| MAILGUN_API_KEY | your_mailgun_api_key || MAILGUN_DOMAIN | your_mailgun_domain || MAILGUN_URL | your_mailgun_url |
部署
🌐 Deployment
要部署项目并使用其他方的电子邮件提供商,请推送之前的更改。这将触发 Strapi Cloud 项目的重建和新部署。
🌐 To deploy the project and utilize another party email provider, push the changes from earlier. This will trigger a rebuild and new deployment of the Strapi Cloud project.
一旦应用构建完成,项目将使用新的电子邮件提供商。
🌐 Once the application finishes building, the project will use the new email provider.
如果你想创建自定义电子邮件提供商,请参阅 CMS 文档中的 电子邮件提供商 文档。
🌐 If you want to create a custom email provider, please refer to the Email providers documentation in the CMS Documentation.