Class: ActionMailer::Base

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

Overview

Adds sending email through an ActiveRecord table as a delivery method for ActionMailer.

Instance Method Summary collapse

Instance Method Details

#ar_mailer_attribute(key, value = nil) ⇒ Object

Sets a custom email class attribute. It can be used if the user wants to set custom attributes on his email records, e.g. to track them later. They are automatically set as attributes in the resulting AR record, so make sure that they actually exist as database columns!

Examples:

Setting a client id to track which client sent the email

ar_mailer_attribute :client_id, @client.id


17
18
19
20
21
22
23
24
25
# File 'lib/action_mailer/ar_mailer.rb', line 17

def ar_mailer_attribute(key, value = nil)
  attrs = ar_mailer_setting(:custom_attributes) || {}
  if value
    attrs[key.to_s] = value
    ar_mailer_setting(:custom_attributes, attrs)
  else
    attrs[key.to_s]
  end
end

#ar_mailer_delivery_time(new_time = nil) ⇒ Object

Sets a delivery time for this email. If left at nil, the email is sent immediately.



38
39
40
# File 'lib/action_mailer/ar_mailer.rb', line 38

def ar_mailer_delivery_time(new_time = nil)
  ar_mailer_setting(:delivery_time, new_time)
end

#ar_mailer_smtp_settings(new_settings = nil) ⇒ Object

Sets custom SMTP settings just for this email



30
31
32
# File 'lib/action_mailer/ar_mailer.rb', line 30

def ar_mailer_smtp_settings(new_settings = nil)
  ar_mailer_setting(:smtp_settings, new_settings)
end