It would be nice to have mail interceptor be able to modify the message to prevent delivery. Alternatively it would be nice to also prevent delivery in the mailer itself.
The use cases are as follows:
User is unsubscribed and you really want to prevent emails being sent to such users.
User has a guest account with a temp internal email address, which you do not want to send emails to.
The email content may be spammy and you want to prevent that delivery.
As such you could do each by wrapping more code around the MyMailer.mail_action(args)/.deliver pattern but it gets repetitive quickly.
This is not environment specific which is already handled very well in Rails since ages, this is more transactional. If we can already do this easily, feel free to point me to the right direction. Happy to send patch in due time if this is acceptable.
Possible routes i’m thinking are to add options to mail itself (:perform_delivery => determine_delivery(args)) and/or adding ability to prevent delivery from interceptor.
Having the ability to easily comply to CAN-spam and other email legislation without having to add an if clause to everywhere you are sending out email would be nice.
If an interceptor can cleanly stop the delivery even for say Devise or
other dependencies initiated emails, it would provide a consistent
behaviour through the apps, which would be neat.
Seems you cant prevent deliveries from interceptor as yet. I understand that checking on the user model before delivering is always going to be hard/unclean from interceptor (how is the interceptor going to get hold of the user model anyway?) but preventing deliveries from interceptors shouldnt be.
I still havent thought how I can cleanly prevent all deliveries to some users use case but at the very least I could flag them in each mailer action where the mail is being sent. Another way I’m thinking this could be prevented is to override the “email” reader in the user model and return an address that could help the interceptor prevent delivery.
The question was whether a patch for this functionality would be useful, I personally would find it useful. And on that front we’re done.
If you want to talk about alternate implementations using existing Rails functionality please move the conversation over to Rails-Talk list. If you have questions or need advice cc/ me in a pull request.