Invalid login: Application-specific password required and how to solve it

Jonas K
2 min readSep 21, 2022

I was working on this tiny NodeJS project, which literally was only sending an email as a notification.

I was using Gmail for this, and every time I ran the script, I got this error message

Invalid login: Application-specific password required

And a tiny preview of the script using nodemailer

import nodemailer from “nodemailer”;const transporter = nodemailer.createTransport({
service: “Gmail”,
auth: {
user: myGmail,
pass: gmailPassword // <-- Generated pass. Keep reading.
}
});
const mailOptions = {
from: myGmail,
to: myGmail,
subject: "It works!",
html: `You just received a mail!`
};
transporter.sendMail(mailOptions, function (err, info) {
if (err) console.log(err);
else console.log(info);
});

How to solve it

Using Gmail, you can’t be using your normal password to your Gmail account. You have to create an application password. Here is how.

  1. Click on your profile and select Manage your Google Account
  2. Select Security
  3. Below Signing in to Google select App passwords
  4. Click Select app and choose Custom name
  5. Name it either nodemailer or whatever you prefer

Now a popup will be shown, with a unique password for this specific app.

Copy this password and use it as the password in the NodeJS script.

That’s it! Now try to run your script again and you should receive a mail using Gmail and nodemailer

--

--

Jonas K
Jonas K

Written by Jonas K

Building stuff on the world wide web. Hi👋

No responses yet