2017-08-02 66 views
1

我无法使用Node.js发送邮件。我收到下面的错误。无法使用Nodemailer和Node.js发送邮件

{ 
    "error": { 
     "code": "EAUTH", 
     "response": "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvp\n534-5.7.14 j_smRtzyG0TYeMSMFUYlhfCGtpt9DmDE4ZR140rMTKNkk0ZwgtIEQ6Kik51kVBedggHrBA\n534-5.7.14 3mM-ha-68KYhP-IPiHTVQkjUj6HlwdSciwJUgyRqIYKTxTtA9N96CmRzCRiPpIPMf6UGu3\n534-5.7.14 ismcOTMvxqQK2naujp_fgkbLjzwPMj47j5cOoaWdIkdwy4qmqMXnw8ib3sdkRfBeUgjVGB\n534-5.7.14 iiSXqql1vBLMkKnk_HNyGdeQu8OwI> Please log in via your web browser and\n534-5.7.14 then try again.\n534-5.7.14 Learn more at\n534 5.7.14 https://support.google.com/mail/answer/78754 k97sm25351307qkh.29 - gsmtp", 
     "responseCode": 534, 
     "command": "AUTH PLAIN" 
    } 
} 

我正在解释下面的代码。

var nodemailer = require("nodemailer"); 
    var smtpTransport = nodemailer.createTransport({ 
     service: 'Gmail', 
     auth: { 
      user: '[email protected]', 
      pass: '********' 
     } 
    }); 
    rand=crypto.randomBytes(20).toString('hex'); 
    host=req.get('host'); 
    link="http://"+req.get('host')+"/api/users/verify?id="+rand; 

mailOptions={ 
       from: "[email protected]", 
       to : email, 
       subject : "Please confirm your Vodex account", 
       html : "Hello,<br> Please Click on the link to verify your Account.<br><a href="+link+">Click here to verify</a>" 
} 
    smtpTransport.sendMail(mailOptions,function(error, response){ 
     if (error) { 
        var data={'error':error}; 
        res.send(data); 
     }else{ 
        db.f_user_login.update({_id : docs._id },{$set:{verification_id:rand}},function(err,doc){ 
     if (!err) { 
        var edata=[{"email": docs.email,"dob": docs.dob,"created_date":docs.created_date ,"id": docs._id,"updated_date":docs.updated_date}]; 
        var data={"statusCode": 200,"data":edata ,"message": "The user registered successfull and an email is sent to your registered email for account verification."}; 
        res.send(data); 
       } 
      }) 
     } 
    }) 

此代码工作正常进行localhost:8989,但现在我已经部署在Heroku上的代码和我的网址是这样https://node-fgdp.herokuapp.com/api/users/signup。在这里,我无法发送邮件并获取上述错误。我需要使用nodemailer和Node.js发送邮件。

回答

1

作为安全防范措施,Google可能会要求您在登录新设备或应用程序时完成额外步骤,称为解锁验证码

您可能需要手动才能访问您的Google帐号。使用浏览器

登录到您的谷歌帐户,然后访问以下链接来解锁: https://accounts.google.com/DisplayUnlockCaptcha

点击允许按钮后,你应该可以看到消息:

帐户访问启用。请尝试从新设备或应用程序再次登录您的Google帐户。

参考
https://support.google.com/mail/answer/7126229?visit_id=1-636373008143011090-3861871695&rd=2#cantsignin