简体   繁体   中英

Invalid login details in Nodemailer (Node.js)

Been trying to implement a simple mail script using in . 实现一个简单的邮件脚本。 This implementation is based on the and I used this link as reference. ,我使用此链接作为参考。 Now I am facing the below error

{ [Error: Invalid login]

code: 'EAUTH', response: '535-5.7.8 Username and Password not accepted. Learn more at\\n535 5.7.8 https://support.google.com/mail/answer/14257 qe3sm505011pbc.73 - gsmtp', responseCode: 535 }

And the fallowing is the code that I used

var nodemailer = require('nodemailer');
var generator = require('xoauth2').createXOAuth2Generator({
    user: 'bharathvijay38',
    clientId: '***************',
    clientSecret: '***************',
    refreshToken: '***************',
    accessToken: '***************'
});

var transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
        user: 'xxxxx@xxxxx.xxx',
        pass: '************',
        xoauth2: generator
    }
});

transporter.sendMail({
    from: 'xxxxx@xxxxx.xxx',
    to: 'xxxxx@xxxxx.xxx',
    subject: 'hello!',
    text: 'Hello there !'
    }, function(error, info){
    if(error) {
        return console.log(error);
    }

    console.log("Message sent: "+info);
});

I am new to node.js and server side scripting. So please kindly help me out

Why do you need the xoauth2 options?

According to Nodemailer

This is the basic usage

var transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
        user: 'gmail.user@gmail.com',
        pass: 'userpass'
    }
});

Where the user is, your Gmail username and the password is, your Gmail password.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM