You are here: Home Solidarrow Ruby on Rails Solidarrow Cheatsheets

* ActionMailer Cheatsheet

ActionMailer is the Rails framework which handles email delivery. This comprehensive cheatsheet will help your email on its way.

Mailer Model

To use ActionMailer, you need to create a mailer model. Emails are defined by creating methods within the mailer model which are then used to set variables to be used in the mail template, to change options on the mail, or to add attachments.

Mailer model generator

    ruby script/generate mailer NameOfMailer method1 method2 method3

Example mailer model

    class OrderMailer < ActionMailer::Base

        def confirm(order,sent_at = Time.now)
            subject    "Subject line goes here"
            body       :order => order
            recipients ["bill@microsoft.com", "steve@apple.com"]
            from       "david@dizzy.co.uk"
            sent_on    sent_at
        end    
    end