【发布时间】:2014-10-30 20:15:36
【问题描述】:
我已经完成了使用带有 AngularJS 和 NodeJS 的 Nodemailer 发送电子邮件的基本电子邮件设置,并且我已经将项目部署在 heroku 上。
当我在 heroku 上运行应用程序时,电子邮件似乎工作得很好,但是当我将它部署到 Heroku 时,没有发送电子邮件。
对于身份验证,我使用的是 Gmail 地址,并且我还有一个 bcc 到另一个 Gmail 地址。所以from 和bcc 地址是两个不同的Gmail 地址。 from地址与认证地址相同。
有人可以帮我解决这个问题吗?
编辑:添加代码
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'foobar@gmail.com',
pass: 'foobar'
}
});
router.post('/send',function(req,res){
var mailOptions = {
from: 'Foo Bar ✔ <foobar@gmail.com>',
to: req.body.email,
subject: "Hello " + req.body.email,
text: 'Hello ' + req.body.email + '✔',
html: "<p>Hello " + req.body.email + " </p>",
bcc: "fred@gmail.com"
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info.response);
res.send(200);
}
});
});
【问题讨论】:
-
请附上错误信息。
-
@PeterLyons:错误:登录无效,响应代码:534,代码:'EAUTH'。
-
嗯,有什么理论吗?对我来说似乎很明显是错误的凭据。
-
@PeterLyons:是的,看起来我必须去accounts.google.com/DisplayUnlockCaptcha 并从我的 gmail 帐户中关闭此安全预防措施,以允许通过 heroku 部署我的应用程序的机器成为能够使用nodemailer通过我的gmail帐户发送电子邮件。 gmail 的好东西。
-
酷。请参阅nodemailer warning about trying to send bulk mail with services not explicitly intended for that。考虑从 mailgun、postmarkapp、sendgrid、amazon SES 等应用程序切换到专为事务性电子邮件设计的真实服务。
标签: node.js angularjs email heroku nodemailer