Class: ActionMailer::ARMailer
- Defined in:
- lib/action_mailer/ar_mailer.rb
Overview
Adds sending email through an ActiveRecord table as a delivery method for ActionMailer.
Converting to ActionMailer::ARMailer
Go to your Rails project:
$ cd your_rails_project
Create a new migration:
$ ar_sendmail --create-migration
You’ll need to redirect this into a file. If you want a different name provide the –table-name option.
Create a new model:
$ ar_sendmail --create-model
You’ll need to redirect this into a file. If you want a different name provide the –table-name option.
Change your email classes to inherit from ActionMailer::ARMailer instead of ActionMailer::Base:
--- app/model/emailer.rb.orig 2006-08-10 13:16:33.000000000 -0700
+++ app/model/emailer.rb 2006-08-10 13:16:43.000000000 -0700
@@ -1,4 +1,4 @@
-class Emailer < ActionMailer::Base
+class Emailer < ActionMailer::ARMailer
def comment_notification(comment)
from comment.author.email
You’ll need to be sure to set the From address for your emails. Something like:
def list_send(recipient)
from '[email protected]'
# ...
Edit config/environment.rb and require ar_mailer.rb:
require 'action_mailer/ar_mailer'
Edit config/environments/production.rb and set the delivery agent:
$ grep delivery_method config/environments/production.rb
config.action_mailer.delivery_method = :activerecord
For Rails 1.x and older:
$ grep delivery_method config/environments/production.rb
ActionMailer::Base.delivery_method = :activerecord
Run ar_sendmail:
$ ar_sendmail
You can also run it from cron with -o, or as a daemon with -d.
See ar_sendmail -h for full details.
Alternate Mail Storage
If you want to set the ActiveRecord model that emails will be stored in, see ActionMailer::ARMailer::email_class=
Class Method Summary collapse
-
.email_class ⇒ Object
Current email class for deliveries.
-
.email_class=(klass) ⇒ Object
Sets the email class for deliveries.
-
.view_paths ⇒ Object
Hack around class_inheritable_accessor being lame.
-
.view_paths=(path) ⇒ Object
Hack around class_inheritable_accessor being lame.
Instance Method Summary collapse
-
#perform_delivery_activerecord(mail) ⇒ Object
Adds
mailto the Email table.
Class Method Details
.email_class ⇒ Object
Current email class for deliveries.
80 81 82 |
# File 'lib/action_mailer/ar_mailer.rb', line 80 def self.email_class @email_class ||= Email end |
.email_class=(klass) ⇒ Object
Sets the email class for deliveries.
87 88 89 |
# File 'lib/action_mailer/ar_mailer.rb', line 87 def self.email_class=(klass) @email_class = klass end |
.view_paths ⇒ Object
Hack around class_inheritable_accessor being lame
94 95 96 |
# File 'lib/action_mailer/ar_mailer.rb', line 94 def self.view_paths # :nodoc: superclass.view_paths end |
.view_paths=(path) ⇒ Object
Hack around class_inheritable_accessor being lame
101 102 103 |
# File 'lib/action_mailer/ar_mailer.rb', line 101 def self.view_paths=(path) # :nodoc: superclass.view_paths = path end |
Instance Method Details
#perform_delivery_activerecord(mail) ⇒ Object
Adds mail to the Email table. Only the first From address for mail is used.
109 110 111 112 113 114 115 116 |
# File 'lib/action_mailer/ar_mailer.rb', line 109 def perform_delivery_activerecord(mail) email_class = ActionMailer::ARMailer.email_class mail.destinations.each do |destination| email_class.create :mail => mail.encoded, :to => destination, :from => mail.from.first end end |