我是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" <[email protected] /cdn-cgi/l/email-protection>',
to : mail_id, //[email protected] /cdn-cgi/l/email-protection
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;
这是我用于向不同用户发送电子邮件的程序。但我越来越登录无效。我不知道为什么会这样。我是 Node.js 和服务器端脚本的新手。
我使用我的 Gmail 用户名和密码作为凭据。
请帮我。
原因之一可能是 Gmail 的“现代安全标准”保护。
检查您的 Gmail 收件箱中是否有任何主题为“Google 帐户:登录尝试被阻止”的新邮件
如果是,请打开邮件并单击链接https://www.google.com/settings/security/lesssecureapps https://www.google.com/settings/security/lesssecureapps
将“访问不太安全的应用程序”设置为“打开”。再试一次,现在应该可以工作了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)