如何让 Strapi 电子邮件插件显示在配置下拉列表中

Jos*_*ins 5 strapi

我正在尝试配置 Strapi v3.0.0-alpha.19 服务器以能够发送电子邮件,特别是用于重置忘记的密码。很难为此找到足够的文档,但我在类似问题的答案中读到的是,我需要安装提供程序包,例如strapi-provider-email-nodemailer,然后设置 SMTP 服务器(一条具有砖块透明度的指令) 。但是,当我在 project-folder/strapi 中安装包,然后重新加载http://localhost:1337/admin/plugins/email/configurations/development 时,提供程序的下拉列表仍然只包含默认提供程序 Sendmail。

我尝试在 Docker 容器中重建 Strapi API,但这没有任何区别。

我希望 Nodemailer 在刷新页面后或至少在重建 API 后出现在下拉列表中,但这并没有发生。我需要采取哪些步骤才能指定 Nodemailer 作为我的电子邮件提供商?

小智 1

考虑到您已经添加了strapi-email-nodemailerstrapi-provider-email-nodemailer,下一步应该是添加配置。

要添加配置,请在plugin.js. 如果没有plugin.js,请在根config文件夹中创建一个。

module.exports = ({ env }) => ({
  email: {
    provider: "nodemailer",
    providerOptions: {
      nodemailer_default_from: "default_from_email@example.com",
      nodemailer_default_replyto: "default_replyto_email@example.com",
      host: "smtp.gmail.com, // Add your smtp host over here
      port: "995", // Add port number
      password: "<below-email-password>,
      username: "<email-address>",
      authMethod: "SMTP", // Auth method
    }
  },
});
Run Code Online (Sandbox Code Playgroud)

您可以将上述配置保存在环境文件中并从那里使用它。

要以编程方式发送电子邮件,请在控制器中添加以下代码:

await strapi.plugins['email'].services.email.send({
  to: 'mail@example.com', // email recipient
  from: 'sender@example.com', // email sender
  subject: 'Email subject line', 
  text: 'Email body should come here'
});
Run Code Online (Sandbox Code Playgroud)