Invalid login NodeMailer

I am new to node.js. programming I use the nodemailer module to send 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 letters to other users. But I get an invalid entry . I do not know why this is happening. I am new to node.js scripts and server side.
I use gmail username and password for credentials.
Please help me.

+14
source share
4 answers

Have you double checked your credentials? Also, have you double-checked your "from" address to match your email address?

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

https://github.com/andris9/Nodemailer

An invalid login indicates invalid or invalid credentials.

+8
source

One of the reasons may be the "modern security standard" from Gmail.

Verify that the gmail inbox for any new mail has the subject "Google Account: Login Attempt Blocked"

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

set "Access for less secure applications" to "Enable". Try again, it should work now.

+27
source

U need to enable protection for applications:

| * | If you use gmail,

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

| * | If you use yahoo,

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

| * | If you use Live or Hotmail, there is no need to activate anything.

 Use : service: 'hotmail', 
+12
source

In particular, there are 2 problems: either you do not have less secure applications https://myaccount.google.com/lesssecureapps enabled or you do not have the unlock code https://accounts.google.com/DisplayUnlockCaptcha enabled , you need to enable them both.

+1
source

Source: https://habr.com/ru/post/1206952/


All Articles