Last active
September 30, 2015 07:47
-
-
Save jeffrafter/1746973 to your computer and use it in GitHub Desktop.
Abortable Action Mailer (no longer needed)
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
| module AbortableMailer | |
| class UndeliverableMailMessage < Mail::Message | |
| def self.deliver | |
| false | |
| end | |
| def self.deliver! | |
| false | |
| end | |
| end | |
| class AbortDeliveryError < StandardError | |
| end | |
| class Base < ActionMailer::Base | |
| def abort_delivery | |
| raise AbortDeliveryError | |
| end | |
| def process(*args) | |
| begin | |
| super *args | |
| rescue AbortDeliveryError | |
| self.message = AbortableMailer::UndeliverableMailMessage.new | |
| end | |
| end | |
| end | |
| end | |
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 Notification < AbortableMailer::Base | |
| def user_email(user_id) | |
| abort_delivery if unsubscribed?(user_id) | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: as of Rails 3.2.9 this is no longer necessary. Instead you can use the built in NullMail class: