0.01
Low commit activity in last 3 years
There's a lot of open issues
No release in over a year
Applications that have complex email sending logic have DRYness problems. ActiveMailer solves that by making a legitimate email model where all sending logic belongs. It is also capable of acting as an audit trail for email sending.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1.0
>= 0
>= 0
>= 1.3.5
~> 0.7.0

Runtime

>= 5.1
 Project Readme

ActiveMailer

Email needs to have somewhere to put the business logic surrounding it, and the controller is not the place for that.

See the disagreement:

Installation

  1. Add gem "active_mailer" to your Gemfile and run bundle install

  2. Run rails generate active_mailer:install

  3. Run rake db:migrate

Basic Usage

There's only a partial generator. In the mean time, making a new ActiveMailer class can be done like this.

  1. Run rails generate model FooEmail --no-migration --parent ActiveMailer::Base, you can pass any additional columns just like you would for a normal generate model.

  2. Run rails generate active_mailer:migration FooEmail

  3. Make the template for your email (in this case called foo_email.rb) in app/views/active_mailer/base/default_action_mailer/foo_email.html.erb

You're ready! You can send your email by making an instance of FooEmail, setting the appropriate details, and calling send!.

> f = FooEmail.new(:subject => "My Awesome Email", :sender => "noreply@example.com",
>                  :recipients => "test@example.com")
=> #<FooEmail id: nil, blahblahblah>

> f.send!
=> true

Advanced Usage

If your email is always going to have the same subject, sender, bcc, etc, then you can set those in the ActiveMailer object. Remember that it's really just an ActiveRecord object, so you can do anything in this class you can do in ActiveRecord.

Here's an example of using ActiveRecord associations to make sure there's a user for the email. It also includes setting the subject and sender by default.

class BeerEmail < ActiveMailer::Base
  belongs_to :user

  validates_presence_of :user

  def after_initialize
    self.subject = "It's Beer O'Clock"
    self.sender  = "itstime@beeroclock.com"
  end
end

Contributing

Setup the project with script/setup.

We use the Appraisal gem to test against multiple versions of Rails. By default rake will test every supported version of Rails, but you can isolate a specific vesion by using appraisal rails4.1 rake.

The tests use a micro Rails app that you should know about.

Bugs/Feature

Authors

  • Matt Gordon
  • Elijah Miller

Copyright (c) 2009-2015 Expected Behavior, LLC, released under the MIT license