代码之家  ›  专栏  ›  技术社区  ›  Joseph Collins

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

  •  0
  • Joseph Collins  · 技术社区  · 7 年前

    我正在尝试配置Strapi v3.0.0-alpha.19服务器,以便能够发送电子邮件,特别是用于重置忘记的密码。很难找到足够的文档,但是我在 questions like this one 我需要安装提供程序包,例如。 strapi-provider-email-nodemailer ,然后设置SMTP服务器(具有砖块透明度的指令)。但是,当我在project folder/strapi中安装包,然后重新加载时 http://localhost:1337/admin/plugins/email/configurations/development

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

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

    0 回复  |  直到 7 年前
        1
  •  1
  •   saboradu94    6 年前

    在较新的Strapi版本中,您还必须在电子邮件插件设置中手动更改电子邮件提供程序,因为电子邮件提供程序下拉列表不再可用( https://github.com/strapi/strapi/pull/6195 ).经过数小时的研究,我刚用amazon ses做了这件事,它成功了。我不知道这是否是正确的方法,但这肯定是我在很长时间后找到的唯一方法。

    去 api/node_modules/strapi-plugin-email/config/settings.js 并将提供程序更改为所需的提供程序。

    您可能应该这样更改您的:

    module.exports = {
      provider: 'nodemailer',
      providerOptions: {},
      settings: {
        defaultFrom: 'Strapi <no-reply@strapi.io>',
      },
    };
    
        2
  •  0
  •   Ashish Kumar    6 年前

    考虑到你已经把两者都加上了 strapi-email-nodemailer 和 strapi-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
        }
      },
    });
    

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

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

    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'
    });