Skip to content

Instantly share code, notes, and snippets.

@simonfranzen
Last active June 6, 2019 14:03
Show Gist options
  • Save simonfranzen/1e5f058f1d0235e15a2fdd97a03f313a to your computer and use it in GitHub Desktop.
Save simonfranzen/1e5f058f1d0235e15a2fdd97a03f313a to your computer and use it in GitHub Desktop.
RubyOnRails E-Mail Whitelisting for Mailer
class EmailInterceptor
# just an example to allow only *@zauberware.com emails
REGEX_WHITELIST = /.*@zauberware\.com/
def self.delivering_email(message)
if !in_whitelist?(message.to.first)
message.perform_deliveries = false
end
end
def self.in_whitelist?(email)
email.match(REGEX_WHITELIST) ? true : false
end
end
# usage:
# create a file under app/initializers/
# file should include
# ActionMailer::Base.register_interceptor(EmailInterceptor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment