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 Configuration Methods

recipients = [array] or "string"

A string containing the email of address of the recipient, or an array of strings containing email addresses of multiple recipients. Will use the email's To: header.

sent_on = Time object

A Time object which will be used to set the Date: header of the email. If not specified, then the current time and date will be used.

subject = "string"

The subject line to be used to set the email's Subject: header.

from = [array] or "string"

A string containing the email address to appear on the From: line of the email being created, or a array of strings containing multiple email addresses in the same format as recipients.

body = {hash}

The body method sets instance variables to be available in the view template. For example, to make the variables order and name accessible as @order and @name respectively in your view template, use...

    body :order => order, :name => name

attachment = {hash} or block

Enables you to add attachments to your email message.

    attachment :content_type => "image/jpeg", :body => File.read("an-image.jpg")
      attachment "application/pdf" do |a| 
        a.body = generate_your_pdf_here()
      end

bcc = [array] or "string"

Blind carbon copy recipients in the same format as recipients.

*cc* = [array] or "string"

Carbon copy recipients in the same format as recipients

content_type = "string"

Set the content type of the message. Defaults to text/plain

headers = {hash}

A hash containing name/value pairs to be converted into abitrary header lines. For example...

    headers "X-Mail-Count" => 107370

mime_version = "string"

The mime version for the message. Defaults to 1.0

charset = "string"

The charset for the body and to encode the subject. Defaults to UTF-8

implicit_parts_order = [array]

When an email is built implicitly, this variable controls how the parts are ordered. Defaults to ["text/html", "text/enriched", "text/plain"]. Items that appear first in the array have higher priority in the receiving mail client and appear last in the mime encoded message.