gpt4 book ai didi

javascript - node.js nodemailer gmail错误

转载 作者:IT老高 更新时间:2023-10-28 23:14:03 25 4
gpt4 key购买 nike

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

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: 'myemail@gmail.com', // my mail
pass: 'mypassword'
}
});
var mailOptions = {
from: 'Fred Foo ✔ <foo@blurdybloop.com>', // sender address
to: 'myemail@gmail.com', // 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)

但是当我运行它时,它会抛出“登录”错误,虽然我的名字/密码是正确的,整个错误看起来像这样

{ [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' }

我必须在我的 gmail acc 中设置什么以允许它从那里发送电子邮件,或者我该如何解决它

最佳答案

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

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

var transport = nodemailer.createTransport(smtpTransport({
service: 'gmail',
auth: {
user: 'myemail@gmail.com', // my mail
pass: 'mypassword'
}
}));

并尝试在您的谷歌帐户中启用此功能: https://www.google.com/settings/security/lesssecureapps

我真的认为这应该是你的身份验证问题

关于javascript - node.js nodemailer gmail错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32447210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com