1

当我将此配置用于 Nodemailer 时:

const transporter = nodemailer.createTransport({
  service: process.env.EMAIL_SERVICE,
  auth: {
    user: process.env.EMAIL_USER,
    pass: process.env.EMAIL_PASSWORD
  }
});

变量:

EMAIL_SERVICE: 'Hotmail',
EMAIL_USER: 'MyEmail@outlook.com',
EMAIL_PASSWORD: 'MyPassword'

我这样发送电子邮件:

transporter.sendMail({
  to: email,
  subject: 'Confirmar cambio de contraseña',
  html: `Para cambiar la contraseña entre a <a href="${url}">${url}</a> <br> Este token solo dura 24 horas.`
});

在开发中它工作得很好但是当我现在部署它时,它会抛出这个错误:

在此处输入图像描述

我该如何解决?

这里有一个关于这个的小例子:

https://github.com/MontoyaAndres/NowProblemNodemailer

现在在这里:

https://nowemail-owcypiqzsr.now.sh

谢谢 :)

4

1 回答 1

0

您可能需要添加一个秘密,然后将环境变量添加到您的now.json.

运行这些命令一次以在您的 ZEIT Now 帐户中添加机密(now switch如果您有多个帐户,请使用)。

now secret add email-service 'Hotmail'
now secret add email-user 'MyEmail@outlook.com'
now secret add email-password 'MyPassword'

然后像这样将env密钥添加到您的now.json文件中:

{
  "version": 2,
  "builds": [/* your builds go here */],
  "env": {
    "EMAIL_SERVICE": "@email-service",
    "EMAIL_USER": "@email-user",
    "EMAIL_PASSWORD": "@email-password"
  }
}
于 2019-05-23T11:59:06.127 回答