title: Rails 3: Trying to extend Action Mailer with a module
body: <p>Trying to rewrite an old alias_method_chain to add a filter on outgoing emails, and it isn't working.  I'm pretty sure I've leaving something out/missing something, but I don't know what.</p>
  
  <p>This file is in /lib/outgoing_mail_filter.rb, which is loaded with config/initializers/required.rb</p>
  
  <p>Here's the old code that worked under Rails 2:</p>
  
  <pre><code>class ActionMailer::Base
    def deliver_with_recipient_filter!(mail = @mail) 
      unless 'production' == Rails.env
        mail.to = mail.to.to_a.delete_if do |to| 
          !(to.ends_with?('some_domain.com'))
        end
      end
      unless mail.to.blank?
        deliver_without_recipient_filter!(mail)
      end
    end
    alias_method_chain 'deliver!'.to_sym, :recipient_filter
  end
  </code></pre>
  
  <p>And here's my current attempt at re-writing it:</p>
  
  <pre><code>class ActionMailer::Base
    module RecipientFilter
      def deliver(mail = @mail) 
        super
        unless 'production' == Rails.env
          mail.to = mail.to.to_a.delete_if do |to| 
            !(to.ends_with?('some_domain.com'))
          end
        end
        unless mail.to.blank?
          deliver(mail)
        end    
      end
    end
  
    include RecipientFilter
  end
  </code></pre>
  
  <p>When I run my tests, it doesn't even look like this is being called or anything.  Any help is appreciated</p>