提问者:小点点

node.js nodemailer和nodemailer-sendinblue-transport无法发送电子邮件


我已经创建了一个帐户与sendInBlue,并导入了nodemailer和nodemailer-sendinblue-transport到我的项目中,我正在尝试发送一个简单的确认电子邮件。下面的代码是我如何尝试安装的:

const transporter = nodemailer.createTransport(
  sendinblueTransport({
    auth: {
      apiKey: 'key'
    }
  })
);

下面的代码是我的注册方法中负责发送确认邮件的一节:

return transporter.sendMail({
  to: email,
  from: 'person@gmail.com',
  subject: 'Signup succeeded!',
  html: '<h1>You successfully signed up!</h1>'
});

当我运行我的程序时,注册过程成功,但抛出以下错误,而不是发送电子邮件:

错误:在数据库中找不到键(失败,401)

我读到他们的v2 API可能会贬值,但是他们的客户支持人员说他们仍然提供对nodemailer的支持,问题是什么呢?我也试过sendGrid和Mandrill,但前者有一个不允许我登录的非常错误的网站,而后者需要一个活跃的域来发送电子邮件。

谢谢


共1个答案

匿名用户

您可以通过以下方式解决此问题:

const transporter = nodemailer.createTransport({
    service: 'SendinBlue', // no need to set host or port etc.
    auth: {
        user: 'yourRegisteredEmailOnSendinblue@email.com',
        pass: 'smtp password here'
    }
});

那么您可以将其称为:

transporter.sendMail({
            to: 'recipientEmail@email.com',
            from: 'senderEmail@email.com',
            subject: 'Signup verification',
            html: '<h1>Please verify your email</h1><a href="www.google.com"> 
                   <button>Verify</button>'
        })
                .then((res) => console.`enter code here`log("Successfully sent"))
                .catch((err) => console.log("Failed ", err))