具有Gmail服务的Nodemailer在Heroku上不起作用 [英] Nodemailer with Gmail service not working on heroku

查看:129
本文介绍了具有Gmail服务的Nodemailer在Heroku上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了基本的电子邮件设置,可以使用带有AngularJS和NodeJS的Nodemailer发送电子邮件,并且已经在heroku上部署了该项目.

I've got a basic email setup done for sending email using Nodemailer with AngularJS and NodeJS and I've got the project deployed on heroku.

当我在heroku上运行该应用程序时,电子邮件发送似乎工作正常,但是当我将其部署到Heroku时,则不会发送电子邮件.

The emailing seems to be working just fine when I am running the app on heroku, but when I get it deployed to Heroku no emails are sent.

为了进行身份验证,我使用的是Gmail地址,并且我还有一个 bcc 到另一个gmail地址.因此, from bcc 地址是两个不同的gmail地址. from 地址与用于身份验证的地址相同.

For authenticaion I am using a gmail address and I also have a bcc to another gmail address. So from and bcc addresses are two different gmail addresses. The from address is same as the address used for authentication.

有人可以帮助我解决这个问题吗?

Could somebody help me with resolving this issue?

修改:添加代码

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);
        }
    });        
});

推荐答案

我认为这与Google帐户安全性有关.-由于设备(位置)未知,Google阻止了您登录以使用邮件功能.

I believe this is issue with google account security. - Google blocked your sign in to use the mailing features due to unknown device (location).

验证此步骤的几个步骤:

A few step to verify this:

  • 在本地启动服务器并发送电子邮件.

  • Start your server locally and sends the email.

检查帐户警报中是否存在未知登录.

Check your account alerts for unknown sign in.

这可以通过以下方式暂时解决: https://accounts.google.com/DisplayUnlockCaptcha

This can be temporally resolved by: https://accounts.google.com/DisplayUnlockCaptcha

更持久的解决方案是将您的密码更改为更高级别:

More permanent resolution would be to change your password to a stronger level:

大写字母+小写字母+特殊符号+数字

upper case letter + lower case letter + special symbols + numbers

这篇关于具有Gmail服务的Nodemailer在Heroku上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆