Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Nodemailer stops with Missing credentials for "PLAIN"

ErrorError: Missing credentials for "PLAIN"

Short answer

Nodemailer tried to log in but had no usable credentials. Either auth is there with empty user or pass, or the server does not need a login and auth should be left out or set to false. A pre-3.0 style OAuth block also causes it; use the current OAuth2 form.

  • Applies to Node.js 22, Nodemailer 6
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which auth values Nodemailer really receives. Print whether each is set, not the value.

    node -e "console.log(Boolean(process.env.SMTP_USER), Boolean(process.env.SMTP_PASS))"
  2. 2Match what you see, then jump to its fix

    1. 1The SMTP relay allows your IP, and user is empty or absentThe server needs no login, but an auth object is still sentFix
    2. 2Gmail OAuth, and the settings come from an old tutorialOAuth set up the pre-3.0 wayFix
    3. 3Login is required, and printing whether each value is set gives falseuser or pass is undefined because the environment file was not loadedFix

What does the error look like?

  • Error: Missing credentials for "PLAIN"

Cause 1 of 3

The server needs no login, but an auth object is still sent

1Check

The docs say that if you omit auth entirely, Nodemailer sends without authentication. An auth object with an empty user does not do that.

grep -n "auth" mailer.js

2Fix

Remove the auth block, or set auth to false as the maintainer advises.

const transporter = nodemailer.createTransport({
  host: 'smtp.example.com',
  port: 587,
  secure: false,
  auth: false,
});

3Verify

Send a test message.

node send-test.js

Confirmed by nodemailer.com

Did this fix it?

Cause 2 of 3

OAuth set up the pre-3.0 way

1Check

The maintainer says legacy OAuth usage has not worked since Nodemailer 3.0.0.

npm ls nodemailer

2Fix

Use auth.type OAuth2 with the user, clientId, clientSecret and refreshToken fields shown in the OAuth2 docs.

const transporter = nodemailer.createTransport({
  host: 'smtp.gmail.com',
  port: 465,
  secure: true,
  auth: {
    type: 'OAuth2',
    user: 'user@example.com',
    clientId: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    refreshToken: process.env.REFRESH_TOKEN,
  },
});

3Verify

Send a test message.

node send-test.js

Confirmed by nodemailer.com

Did this fix it?

Cause 3 of 3

user or pass is undefined because the environment file was not loaded

1Check

The auth object needs user and pass for a normal login. Variables from a .env file exist only if something loaded the file. Node.js can do it with --env-file, and it throws if the file is missing.

node --env-file=.env -e "console.log(Boolean(process.env.SMTP_USER))"

2Fix

Start the app with the env file and confirm the names match what mailer.js reads.

node --env-file=.env server.js

3Verify

Run the check again. Both values should print true.

node --env-file=.env -e "console.log(Boolean(process.env.SMTP_USER), Boolean(process.env.SMTP_PASS))"

Confirmed by nodejs.org

Did this fix it?

How do I stop it coming back?

  • Fail at start-up when SMTP_USER or SMTP_PASS is missing instead of building a transport with undefined.
  • Build the auth block only when a user is configured.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.