Class: ActionMailer::DeliveryMethodActiveRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mailer/ar_mailer.rb

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ DeliveryMethodActiveRecord

The delivery method seems to be called with a settings hash from the mail gem.



72
73
74
# File 'lib/action_mailer/ar_mailer.rb', line 72

def initialize(settings)
  @settings = settings
end

Instance Method Details

#deliver!(mail) ⇒ Object

Actually creates the email record in the database



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/action_mailer/ar_mailer.rb', line 79

def deliver!(mail)
  if mail['ar_mailer_settings']
    ar_settings                = YAML::load(mail['ar_mailer_settings'].value).stringify_keys
    mail['ar_mailer_settings'] = nil
  else
    ar_settings = {}
  end

  email_options = {}
  email_options[:delivery_time] = ar_settings.delete('delivery_time')
  email_options[:smtp_settings] = ar_settings.delete('smtp_settings').try(:symbolize_keys)
  email_options[:mail]          = mail.encoded
  email_options[:from]          = (mail['return-path'] && mail['return-path'].spec) || mail.from.first
  email_options.reverse_merge!(ar_settings['custom_attributes'] || {})

  mail.destinations.each do |destination|
    ArMailerRevised.email_class.create!(email_options.merge({:to => destination}))
  end
end