NodeMailer Invalid Login

2019-03-18 10:26发布

I am new to node.js programming .I am using nodemailer module for sending emails.

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;

This is my program for sending emails to different users. But I am getting Invalid Login . I don't have any idea why this is coming . I am new to node.js and server side scripting.
I am using my gmail username and password for credentials.
Please help me.

3条回答
手持菜刀,她持情操
2楼-- · 2019-03-18 10:39

U need to Enable Security for Apps :

|*| If u r using gmail,

Use :

    service: 'gmail',

Goto : 

    https://myaccount.google.com/lesssecureapps

Enable : 

    Allow less secure apps: ON

|*| If u r using yahoo,

Use :

    service: 'yahoo',

Goto : 

    https://login.yahoo.com/account/security

Enable : 

    Allow apps that use less secure sign in

|*| If u r using Live or Hotmail, No need to enable anything.

Use :

    service: 'hotmail',
查看更多
等我变得足够好
3楼-- · 2019-03-18 10:45

Did you double-check your login credentials? Also did you double-check your "from" adress to match your email?

I used the nodemailer for some tests 3 weeks ago with the gmail example given on the github page and it worked like a charm:

https://github.com/andris9/Nodemailer

Invalid login indicates mistyped/wrong credentials.

查看更多
Root(大扎)
4楼-- · 2019-03-18 10:48

One reason could be the 'modern security standard' protection from Gmail.

Check you gmail inbox for any new mail having subject "Google Account: sign-in attempt blocked"

If yes, open the mail and click on the link https://www.google.com/settings/security/lesssecureapps

set 'Access for less secure apps' to 'Turn on'. Try again, it should be working now.

查看更多
登录 后发表回答