Last active
June 6, 2019 14:03
-
-
Save simonfranzen/1e5f058f1d0235e15a2fdd97a03f313a to your computer and use it in GitHub Desktop.
RubyOnRails E-Mail Whitelisting for Mailer
This file contains hidden or 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 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