首页 文章

NodeMailer无效登录

提问于
浏览
10

我是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用户名和密码来获取凭据 .
请帮我 .

3 回答

  • 6

    一个原因可能是Gmail的“现代安全标准”保护 .

    检查gmail收件箱中是否有任何主题为“Google帐户:登录尝试已被屏蔽”的新邮件

    如果是,请打开邮件并单击链接https://www.google.com/settings/security/lesssecureapps

    将“访问不太安全的应用程序”设置为“打开” . 再试一次,现在应该可以了 .

  • 23

    您是否仔细检查了登录凭据?您是否也仔细检查了您的“来自”地址以匹配您的电子邮件?

    我在3周前使用nodemailer进行了一些测试,在github页面上给出了gmail示例,它就像一个魅力:

    https://github.com/andris9/Nodemailer

    无效登录表示输入错误/错误凭据 .

  • 8

    U need to Enable Security for Apps :

    | * |如果你使用gmail,

    Use :
    
        service: 'gmail',
    
    Goto : 
    
        https://myaccount.google.com/lesssecureapps
    
    Enable : 
    
        Allow less secure apps: ON
    

    | * |如果你使用雅虎,

    Use :
    
        service: 'yahoo',
    
    Goto : 
    
        https://login.yahoo.com/account/security
    
    Enable : 
    
        Allow apps that use less secure sign in
    

    | * |如果您使用Live或Hotmail,则无需启用任何内容 .

    Use :
    
        service: 'hotmail',
    

相关问题