Nodemailer not working in production

@coelmay your solution didn’t work for me, but in the end I figured it out. The point is one must handle the return value (a Promise) from nodemailer at all levels. In my case, I am using array.map() to send several emails so I had to use const results = await Promise.all(new_shipments.map(email_tracking_numbers)); at the top-level (the handler definition) and email_tracking_numbers is an async function which returns the result of calling sendMail e.g. const mail_res = await transporter.sendMail({.....}); return mail_res;

I’m not a JS person, so I’m not exactly clear why the dev environment doesn’t care about the Promises, but production does. It would be great if this quirk was explained in the documentation because there are so many questions related to this in the forums and on SO. I myself asked about axios some time ago ( Function works locally but wont POST with axios, doesn't log any errors or exceptions - #3 by jcpsantiago ) and I was still clueless when faced with essentially the same issue with nodemailer.

So for anyone finding this (even you future @jcpsantiago :wave:): handle your Promises all the way to the top, always return everything and use await Promise.all if you’re handling an array of promises.

Cheers

2 Likes