The two most important precautions to make in mailing list code

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the web-development category.

Last Updated: 2024-04-25

Imagine you were about to send emails to 10k people. What are the two biggest issues you should consider in your code?

# sample code, but don't read into this much
Sales.where('created_at > ?', 2.years.ago).map do |sale|
  sale.email
end

Here are the two, potentially very damaging issues:

  1. There is no check if the user is subscribed. Unsubscribed people must be filtered out!
  2. There is no check of uniqueness of email receiving messages. If a customer bought many items (many sales) then they'll have many emails - this is not good and would be felt as aggressive.

These two issues must always be accounted for in mailing list code.