Created
September 23, 2012 22:53
-
-
Save jmccartie/3773340 to your computer and use it in GitHub Desktop.
Don't deliver email if the address is on a blacklist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailAddressFilter | |
def self.delivering_email(message) | |
message.perform_deliveries = false | |
# Remove email from message.to if email is on the unsubscribe list | |
tos = message.to.to_a | |
message.to.each do |email| | |
tos.delete(email) if Unsubscribe.find_by_email(email) | |
end | |
message.to = tos # can't delete directly from message.to. probably a better way to do this... | |
return unless message.to.any? | |
# Still have emails? Let's send them! | |
message.perform_deliveries = true | |
end | |
end | |
ActionMailer::Base.register_interceptor(EmailAddressFilter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about
message.to = message.to.select { |email| !Unsubscribe.find_by_email(email) }