## # Adds sending email through an ActiveRecord table as a delivery method for # ActionMailer. # class ActionMailer::Base adv_attr_accessor :priority def create_mail_with_priority create_mail_without_priority @mail.priority = self.priority @mail end alias_method_chain :create_mail, :priority ## # Set the email class for deliveries. Handle class reloading issues which prevents caching the email class. # @@email_class_name = 'Email' def self.email_class=(klass) @@email_class_name = klass.to_s end def self.email_class @@email_class_name.constantize end ## # Adds +mail+ to the Email table. Only the first From address for +mail+ is # used. def perform_delivery_activerecord(mail) destinations = mail.destinations mail.ready_to_send sender = (mail['return-path'] && mail['return-path'].spec) || mail.from.first destinations.each do |destination| self.class.email_class.create :mail => mail.encoded, :to => destination, :from => sender, :priority => mail.priority || 0 end end end