使用ZEIT Now设置环境变量时,Nodemailer无效登录535

时间:2018-08-03 01:17:43

标签: node.js nodemailer zeit-now

当我对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.`
});

在开发中,它可以完美工作,但是当我在Now中部署它时,会抛出此错误:

enter image description here

我该如何解决?

这里有一个小例子:

https://github.com/MontoyaAndres/NowProblemNodemailer

现在就在这里:

https://nowemail-owcypiqzsr.now.sh

谢谢:)

1 个答案:

答案 0 :(得分:0)

您可能需要添加一个secret,然后将环境变量添加到您的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"
  }
}