Seems like executing a return in one of the deliver_* methods of ActionMailer doesn''t cancel the delivery. The template is still read right after the return method has been executed and because all variables in the template are empty, all kinds of errors occur. I need to validate the email (and test whether it actually exists) before a delivery is made and I''m trying to put all that logic inside the delivery methods themselves, but no luck. Anybody know of a solution? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Henrik ---
2008-Nov-05 19:23 UTC
Re: ActionMailer cancel send from one of deliver_* methods
surge wrote:> Seems like executing a return in one of the deliver_* methods of > ActionMailer doesn''t cancel the delivery. The template is still read > right after the return method has been executed and because all > variables in the template are empty, all kinds of errors occur. > > I need to validate the email (and test whether it actually exists) > before a delivery is made and I''m trying to put all that logic inside > the delivery methods themselves, but no luck. > > Anybody know of a solution?I needed this myself just now, and found this thread (on Ruby Forum), so I figured I''d post my solution here for others to find, even though the question was well over a year ago: In my ApplicationMailer that I inherit all others mailers from, I do this: # Allow cancelling mails from within a mailer by doing "raise NotSendingMail". class NotSendingMail < StandardError; end def self.method_missing(*args) super rescue NotSendingMail => e RAILS_DEFAULT_LOGGER.info("Not mailing! #{e}") end Should be pretty self-explanatory. I suppose one could use throw/catch instead of raise/rescue, but I find it reads worse if you want the equivalent of a rescue block. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---