本文介绍了node.js nodemailer gmail错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用node.js发送电子邮件 - nodemailer模块,我的整个代码看起来像

  var http = require ( HTTP); 
var nodemailer = require(nodemailer);
$ b $ http.createServer(function(req,res){
res.writeHead(200,{Content-Type:text / plain});
var transporter = nodemailer.createTransport('SMTP',{
service:'gmail',
auth:{
user:'[email protected]',// my mail
pass :'mypassword'
}
});
var mailOptions = {
from:'Fred Foo✔< [email protected]>',//发件人地址
to:'[email protected]',//同一邮件=想发送给自己
主题:'Hello✔',//主题行
文本:'Hello world✔' ,//明文正文
html:'< b> Hello world✔< / b>'// html body
};
transporter.sendMail(mailOptions,function(error,info ){
if(error){
return console.log(error);
}
console.log('Message sent:'+ info.response);

));
res.end(hllo);
})。listen(4000)


$ $ b $ p

但是当我运行它时,它会抛出登录错误,altought我的名字/传球是正确的整个错误看起来像这样

{[AuthError:Invalid login - 534-5.7.14< https://accounts.google.com/ContinueSi
gnIn?sarp = 1& scc = 1& plt = AKgnsbtWV
534-5.7.14 FHw6FqlXkg3nIQW7AtsO7o0r-4EtD7eTtnrgHeXxeULYqUtHjrnTB9R647mlR7GY9Z4lS
Z
534-5.7.14 WuzYYnNwNBjIyrjNzHk-o9sIV_vIsbjgF5HsFPtJl5S0dSf3eyNCX_E8tQ_Z6s4Z1mUe5
I
534-5.7.14 p8Y5YagzdN5RSkjpB1yTu3TfWHSTLisczIZphhLfhlz-v86tAB8MX-4jRqA51hfJYy0ko
F
534-5.7.14 qytMeIbs1kUZEJzPIabmjRi87DIk>请通过您的网络浏览器和
534-5.7.14登录,然后重试。
534-5.7.14请参阅
534 5.7.14 https://support.google.com/mail/answer/78754 cx1sm17733852wib.0 - gs
mtp]
名称:'AuthError',
data:'534-5.7.14< https://accounts.google.com/ContinueSignIn?sarp = 1& scc = 1& plt
= AKgnsbtWV \r \\\
534-5.7.14 FHw6FqlXkg3nIQW7AtsO7o0r-4EtD7eTtnrgHeXxeULYqUtHjrnTB9R
647mlR7GY9Z4lSz\r\534-5.7.14 WuzYYnNwNBjIyrjNzHk-o9sIV_vIsbjgF5HsFPtJl5S0dSf3ey
NCX_E8tQ_Z6s4Z1mUe5i\r\\\
534-5.7.14 p8Y5YagzdN5RSkjpB1yTu3TfWHSTLisczIZphhLfhlz-v
86tAB8MX-4jRqA51hfJYy0koF\r\\\
534-5.7.14 qytMeIbs1kUZEJzPIabmjRi87DIk>请通过您的网络浏览器登录
,然后再次尝试。\r\\\
534-5.7.14在$ r'\
534 5.7处了解
更多.14 https://support.google.com/mail/answer/78754 cx1sm1773385
2wib.0 - gsmtp',
stage:'auth'}

是否有必须在我的gmail acc中设置允许此发送电子邮件或我如何修复它

解决方案

尝试安装nodemailer-smtp-transport,然后在您的createTransport函数中使用它。

  var smtpTransport = require('nodemailer-smtp-transport'); 

var transport = nodemailer.createTransport(smtpTransport({
service:'gmail',
auth:{
user:'[email protected]',/ / my mail
pass:'mypassword'
}
}));

同时在您的Google帐户中尝试启用此功能:



我真的认为这应该是您的认证问题


Im trying to send a email using node.js - nodemailer module , my whole code looks like

var http=require("http");
var nodemailer=require("nodemailer");

http.createServer(function(req,res){
     res.writeHead(200, {"Content-Type": "text/plain"});
     var transporter = nodemailer.createTransport('SMTP',{
    service: 'gmail',
    auth: {
        user: '[email protected]', // my mail
        pass: 'mypassword'
    }
});
var mailOptions = {
    from: 'Fred Foo ✔ <[email protected]>', // sender address
    to: '[email protected]', // the same mail = want to send it to myself
    subject: 'Hello ✔', // Subject line
    text: 'Hello world ✔', // plaintext body
    html: '<b>Hello world ✔</b>' // html body
};
    transporter.sendMail(mailOptions, function(error, info){
    if(error){
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);

});
    res.end("hllo");
}).listen(4000)

but when i run it , it throws "login" error , altought my name/pass are correct the whole error looks like this

{ [AuthError: Invalid login - 534-5.7.14 <https://accounts.google.com/ContinueSi
gnIn?sarp=1&scc=1&plt=AKgnsbtWV
534-5.7.14 FHw6FqlXkg3nIQW7AtsO7o0r-4EtD7eTtnrgHeXxeULYqUtHjrnTB9R647mlR7GY9Z4lS
z
534-5.7.14 WuzYYnNwNBjIyrjNzHk-o9sIV_vIsbjgF5HsFPtJl5S0dSf3eyNCX_E8tQ_Z6s4Z1mUe5
i
534-5.7.14 p8Y5YagzdN5RSkjpB1yTu3TfWHSTLisczIZphhLfhlz-v86tAB8MX-4jRqA51hfJYy0ko
F
534-5.7.14 qytMeIbs1kUZEJzPIabmjRi87DIk> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14  Learn more at
534 5.7.14  https://support.google.com/mail/answer/78754 cx1sm17733852wib.0 - gs
mtp]
  name: 'AuthError',
  data: '534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt
=AKgnsbtWV\r\n534-5.7.14 FHw6FqlXkg3nIQW7AtsO7o0r-4EtD7eTtnrgHeXxeULYqUtHjrnTB9R
647mlR7GY9Z4lSz\r\534-5.7.14 WuzYYnNwNBjIyrjNzHk-o9sIV_vIsbjgF5HsFPtJl5S0dSf3ey
NCX_E8tQ_Z6s4Z1mUe5i\r\n534-5.7.14 p8Y5YagzdN5RSkjpB1yTu3TfWHSTLisczIZphhLfhlz-v
86tAB8MX-4jRqA51hfJYy0koF\r\n534-5.7.14 qytMeIbs1kUZEJzPIabmjRi87DIk> Please log
 in via your web browser and\r\n534-5.7.14 then try again.\r\n534-5.7.14  Learn
more at\r\n534 5.7.14  https://support.google.com/mail/answer/78754 cx1sm1773385
2wib.0 - gsmtp',
  stage: 'auth' }

is there something i have to set in my gmail acc to allow this to send email from that or how can i fix it

解决方案

Try installing nodemailer-smtp-transport and then use it inside your createTransport function.

var smtpTransport = require('nodemailer-smtp-transport');

var transport = nodemailer.createTransport(smtpTransport({
    service: 'gmail',
    auth: {
        user: '[email protected]', // my mail
        pass: 'mypassword'
    }
}));

And try also while in your google account enabling this: https://www.google.com/settings/security/lesssecureapps

I really think this should be your auth problem

这篇关于node.js nodemailer gmail错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:54