/ nodejs

Lesson - Sending lots of emails with nodemailer

I'm gonna frame the circumstance:

  1. Develop an app that is used to trade assets within an organization
  2. App relies heavily on a mailing service to notifiy users of assets offered for sale
  3. Dev env with local mailer - works mint
  4. push to production
  5. ???
  6. Mailer isn't working

So - time for research

1. Check Logs

Shows literally no errors.

2. Something wrong with prod data?

dump production - load in development, execute function to send notifications, test SMTP server catches all mail

3. Ok - this must be a throttle

Contact email folks -- OUT OF OFFICE
That's okay, I can wait for tomorrow for a response

SUDDENLY A WILD DIRECTOR APPEARS

I need to list some assets

oh no...
sleepover.jpg

4. Debug mails that succesfully sent

Woah, 25 exactly! That's a suspiciously pleasant number
-- Time To Google!

Simple Formula

exchange + throttle = answer

Maximum Messages Per Connection: 20

Well hot damn.

Time to reconfigure nodemailer!

{
  ...
  pool:true,
  maxMessages: 20,
  rateLimit: 20
}

To limit my burden to 20 messages per second (rateLimit) and 20 messages per connection (maxMessages)

Great Success!

Lessons Learned:

  1. Your dev environment can't always be EXACTLY like your production environment - coordinate with your infrastructure guys (Chances are you don't want to be sending real emails in your dev environment, so chances are you won't be using a fully licensed exchange server)
  2. Understanding how the tech your using works is imperative. I didn't know exchange throttled emails, but I know that throttling is often used to prevent overloading servers with potentially malicious requests. Applying general knowledge helped point me in the right direction
  3. Reading the docs is super helpful - This is a lesson most of us learn over and over :)

Happy Hacking!