gmailnodemailergoogle-account

Nodemailer with gmail: Google has disabled "Less secure app access"


How should I use nodemailer with gmail as the google has disabled less secure apps access on every account, I had created two new accounts but could not enable less secure access.
Here is what the google is showing in my new account: enter image description here

Here is my code:


const nodemailer = require('nodemailer')
let transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
      user: "myemail@gmail.com",
      pass: "MyPassword",
    },
  });
  
  let mailOptions = {
    from: 'dsigmatesting@gmail.com',
    to: "akabir247@gmail.com",
    subject: `The subject goes here`,
    html: `The body of the email goes here in HTML`,
    
  };
  
  transporter.sendMail(mailOptions, function (err, info) {
    if (err) {
     console.log(err)
    } else {
      console.log(info)
    }
  });

Please help me in the process of solving this problem.


Solution

  • From the Nodemailer Github repo:

    1. Go to https://myaccount.google.com/security
    2. Enable 2FA
    3. Create App Password for Email
    4. Copy that password (16 characters) into the pass parameter in Nodemailer auth.
    ...,
      auth: {
        user: 'yourmail@gmail.com', 
        pass: 'your_new_app_password', 
      },
    ...