Problem with Nodemailer

Hello everyone,

I migrated 2 websites (PERN Stack) from Heroku yesterday, and there is something that is broken with both of them, Nodemailer. It’s not sending mails anymore (newsletter form, contact form, account activation, password reset, …).

const transporter = nodemailer.createTransport({
  service: 'hotmail',
  auth: {
    user: process.env.MAIL_USER,
    pass: process.env.MAIL_PASS,
  },
});

transporter.verify((error) => {
  if (error) {
    console.log(`[ERROR] - Nodemailer (${process.env.MAIL_USER}:${process.env.MAIL_PASS})`);
  } else {
    console.log('[SUCCESS] - Nodemailer');
  }
});

I tried to verify if my secrets were the problem, but no, I get a failure in the logs with the correct credentials. [ERROR] - Nodemailer (xxx@outlook.com:xxx)

I guess the problem comes from Fly because it’s working perfectly in Heroku and when I launch both the API server and React app on my computer.

Does anyone ever encountered this problem or know where it might come from ?

[REPLY] :bell:
I reply here because i have a reply limit for my first day on the forum.

I don’t know why i didn’t think about logging the error which is the first thing I should do :man_facepalming:.

2022-08-27T15:56:18.655 app[9b2b307d] mad [info] Error: Invalid login: 535 5.7.3 Authentication unsuccessful [FR2P281CA0012.DEUP281.PROD.OUTLOOK.COM]
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at SMTPConnection._formatError (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:787:19)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at SMTPConnection._actionAUTHComplete (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:1539:34)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at SMTPConnection.<anonymous> (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:1493:18)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at SMTPConnection._processResponse (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:950:20)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at SMTPConnection._onData (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:752:14)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at SMTPConnection._onSocketData (/workspace/node_modules/nodemailer/lib/smtp-connection/index.js:191:44)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at TLSSocket.emit (node:events:537:28)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at addChunk (node:internal/streams/readable:324:12)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at readableAddChunk (node:internal/streams/readable:297:9)
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] at Readable.push (node:internal/streams/readable:234:10) {
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] code: 'EAUTH',
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] response: '535 5.7.3 Authentication unsuccessful [FR2P281CA0012.DEUP281.PROD.OUTLOOK.COM]',
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] responseCode: 535,
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] command: 'AUTH LOGIN'
2022-08-27T15:56:18.655 app[9b2b307d] mad [info] }

Well it seems like the logins are wrong but they aren’t. The logs aren’t helping much.
I tried, just to be sure, to put plain email/pass instead of the process.env, same error.
I tried putting the config myself, same error (but it’s also working on my computer).

host: "smtp-mail.outlook.com",
secureConnection: false,
port: 587,
auth: {
    user: "user@outlook.com",
    pass: "password"
},
tls: {
    ciphers:'SSLv3'
}

Personally I use AWS SES so I haven’t, however the first thing I’d do to debug that issue would be to see what Nodemailer is complaining about. I’d log the error, like:

if (error) {
   console.error(error);
}

If it complains about the port being blocked, or the hostname, or SSL, or something else, then you’ve got something to work with :slight_smile:

I don’t think I can fix this. Those websites are just school projects, so I’ll just try to change the mail service. There must be something blocked between Fly and Outlook.

Right now i’m trying SendGrid and the authentification is working :slightly_smiling_face:

I use MailChannels with Cloudflare Workers which makes it dead-simple to send emails (for free!). No DKIM/DMARC/SPF yet.

Our code isn’t public (will soon be), but in the meanwhile see this entry: Sending Email from Cloudflare Workers using MailChannels Send API – Help Center