我是 node.js 编程的新手。我正在使用 nodemailer 模块发送电子邮件。
const nodemailer = require ('nodemailer'),
credentials=require('./credentials.js');
var mailTransport=nodemailer.createTransport({
service:'Gmail',
auth: {
user : credentials.gmail.user,
pass : credentials.gmail.password,
}
});
function sendMail(mail_id){
mailTransport.sendMail({
from: ' "my name" <myname@gmail.com>',
to : mail_id, //user@gmail.com
subject : 'Hello',
text: "Hello How do u do ?",
},function(err,info){
if(err){
console.log('Unable to send the mail :'+err.message);
}
else{
console.log('Message response : '+info.response);
}
});
}
exports.sendMail=sendMail;
这是我向不同用户发送电子邮件的程序。但我得到 Invalid Login 。我不知道为什么会这样。我是 node.js 和服务器端脚本的新手。
我正在使用我的 gmail 用户名和密码作为凭据。
请帮帮我。
最佳答案
其中一个原因可能是 Gmail 的“现代安全标准”保护。
检查您的 gmail 收件箱中是否有任何主题为“Google 帐户:登录尝试被阻止”的新邮件
如果是,打开邮件并点击链接https://www.google.com/settings/security/lesssecureapps
将“安全性较低的应用程序的访问权限”设置为“开启”。再试一次,它现在应该可以工作了。
关于javascript - NodeMailer 登录无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26948516/