javascript - NodeMailer 登录无效

标签 javascript node.js smtp server-side nodemailer

我是 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/

相关文章:

javascript - 列出列的下拉菜单

javascript - 使用 Three.js 绘制尺寸线和 3D 立方体

javascript - 登录后 Firebase 慢重定向?

javascript - 如何告诉 Passport JS 中的 typescript req.user 永远不会被定义?

sql-server - 如何在 mssql(node.js) 中使用 Like 运算符

javascript事件onkeypress事件不会运行

node.js - 在 Mongoose 中填充后查询

Java:发送附件电子邮件时出现异常

python - 使用 Python 发送 Outlook 电子邮件的方法差异

php - 在邮件服务器 PHPMailer 中请求 SMTP 身份验证