Mailgun SMTP authentication error 535 with nodemailer configuration

I keep getting authentication failures when sending emails through nodemailer with Mailgun SMTP settings. The error shows up as:

Email sending failed: Invalid login: 535 Authentication failed
at SMTPTransporter._handleError (/app/node_modules/nodemailer/lib/smtp-transport/index.js:812:21)
at SMTPTransporter._processAuthResponse (/app/node_modules/nodemailer/lib/smtp-transport/index.js:1565:36)
at SMTPTransporter.<anonymous> (/app/node_modules/nodemailer/lib/smtp-transport/index.js:568:28)
at SMTPTransporter._handleResponse (/app/node_modules/nodemailer/lib/smtp-transport/index.js:976:22)
at SMTPTransporter._processData (/app/node_modules/nodemailer/lib/smtp-transport/index.js:778:16)
at TLSSocket.SMTPTransporter._onSocketData (/app/node_modules/nodemailer/lib/smtp-transport/index.js:215:46)
{
  code: 'EAUTH',
  response: '535 Authentication failed',
  responseCode: 535,
  command: 'AUTH PLAIN'
}

I have double checked my Mailgun SMTP credentials multiple times. My host, username, password and port settings are all accurate. What could be causing this authentication problem?

I experienced a similar 535 error despite entering the correct credentials. It turned out my configuration had outdated information. Ensure you’re using the most recent API key or SMTP credentials from your Mailgun dashboard, as these change if regenerated. Additionally, verify if there are any IP restrictions set in your account, as these can interfere with authentication. If the issue persists, consider contacting Mailgun support for further assistance.

Check your Mailgun region endpoint first - if you’re in EU, you need smtp.eu.mailgun.org, not smtp.mailgun.org. This screwed me over for hours once. Everything looked right but I was hitting the wrong server. Also enable less secure app access or check your 2FA settings - they can mess with SMTP auth even when your credentials are correct.

Had this exact issue last month - it was the domain config on Mailgun’s side. Even with the right SMTP credentials, auth fails if your sending domain isn’t verified or you’re sending from an email that doesn’t match your configured domain. Check your Mailgun domain settings and make sure it shows verified. Also, some hosts block outbound SMTP on port 587, so try port 2525 instead (Mailgun supports both). The error’s misleading - it screams authentication when it’s usually domain verification or network blocks.