无法加载电子邮件提供程序“nodemailer”(Strapi)

vof42yt1  于 2023-10-17  发布在  Node.js
关注(0)|答案(2)|浏览(111)

我正在尝试使用nodemailer设置strapi应用程序。
我已经添加了nodemailer依赖与yarn add @strapi/provider-email-nodemailer在官方页面上描述。之后,我将以下配置添加到plugins.js文件中(我已将敏感信息替换为XXXXXXXX):

module.exports = ({ env }) => ({
    email: {
        config: {
            provider: 'nodemailer',
            providerOptions: {
                host: env('SMTP_HOST', 'XXXXXXXX'),
                port: env('SMTP_PORT', 587),
                auth: {
                    user: env('SMTP_USERNAME', 'XXXXXXXX'),
                    pass: env('SMTP_PASSWORD', 'XXXXXXXX'),
                },
                secure: true
            },
            settings: {
                defaultFrom: 'XXXXXXXX',
                defaultReplyTo: 'XXXXXXXX',
            },
        },
    },
});

但是当我尝试用yarn develop绑定Strapi时,我得到以下错误消息:

C:\Dev\Strapi\Projects\strapi>yarn develop
yarn run v1.22.15
$ strapi develop
Building your admin UI with development configuration ...
Admin UI built successfully
[2021-12-27 23:27:51.485] debug: ⛔️ Server wasn't able to start properly.
[2021-12-27 23:27:51.487] error: Could not load email provider "nodemailer".
Error: Could not load email provider "nodemailer".
    at createProvider (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\plugin-email\server\bootstrap.js:23:11)
    at Object.module.exports [as bootstrap] (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\plugin-email\server\bootstrap.js:31:37)
    at Object.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\core\domain\module\index.js:40:47)
    at Object.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\core\registries\modules.js:28:19)
    at async Strapi.runLifecyclesFunctions (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\Strapi.js:463:5)
    at async Strapi.bootstrap (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\Strapi.js:401:5)
    at async Strapi.load (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\Strapi.js:410:5)
    at async Strapi.start (C:\Dev\Strapi\Projects\strapi\node_modules\@strapi\strapi\lib\Strapi.js:161:9)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

我做错了什么?配置看起来很简单,所以我不知道出了什么问题。

hc2pp10m

hc2pp10m1#

你应该安装

yarn add nodemailer

并将其添加到您的发送电子邮件服务中:

var mailObj = {
          to: email,
          subject: template.name,
          from: process.env.FROM_MAIL,
          html: content
        }
    
        let config = {
            mail: {
                type: 'smtp',
                host: process.env.MAIL_HOST,
                secure: false,
                port: 587,
                tls: {
                  rejectUnauthorized: false
                },
                auth: {
                  user: process.env.MAIL_USERNAME,
                  pass: process.env.MAIL_PASSWORD
                }
              }
    let transporter = nodemailer.createTransport(config.mail);
await transporter.sendMail(mailObj);

这将发送一封邮件。

cyej8jka

cyej8jka2#

您需要删除配置部分:

email: {
  provider: 'nodemailer',
  providerOptions: {
    host: env('SMTP_HOST', 'smtp.xxxxxx.xx'),
    port: env('SMTP_PORT', xxx),
    secure: true,
    auth: {
      user: env('SMTP_USERNAME'),
      pass: env('SMTP_PASSWORD'),
    },
  },
  settings: {
    defaultFrom: env('SMTP_FROM_EMAIL'),
    defaultReplyTo: env('SMTP_REPLY_EMAIL'),
  },
},

UPD:对不起,我现在明白了,我使用这个软件包https://www.npmjs.com/package/strapi-provider-email-nodemailer,你使用这个https://www.npmjs.com/package/@strapi/provider-email-nodemailer

相关问题