Skip to content

Instantly share code, notes, and snippets.

@assaf
Created February 1, 2010 00:00
Show Gist options
  • Save assaf/291325 to your computer and use it in GitHub Desktop.
Save assaf/291325 to your computer and use it in GitHub Desktop.
class ActionMailer::Base
# We're using the SendGrid SMTP API to send emails to a large distribution
# list. During testing, we want to validate that each recipient received a
# copy of the email. Do that by looking for emails sent to a distribution
# list and creating multiple copies, one for each recipient.
def perform_delivery_test(mail)
mail.ready_to_send # All duplicates must have same message id
smtpapi = JSON.parse(mail["X-SMTPAPI"].to_s) if mail["X-SMTPAPI"]
if smtpapi && smtpapi["to"]
mail.delete "X-SMTPAPI"
smtpapi["to"].each do |to|
clone = TMail::Mail.parse(mail.to_s)
clone["Delivered-To"] = to
perform_delivery_test clone
end
else
deliveries << mail
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment