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.

Multipart messages

There are two ways to send multipart email messages, explicity by manually defining each part, and implicitly by letting ActionMailer do the donkey work.

Explicitly

You can explicitly define multipart messages using the part method...

    part "text/plain" do |p|
        p.body = render_message("signup-as-plain", :account => recipient)
        p.transfer_encoding = "base64"
    end

    part :content_type => "text/html", :body => render_message("signup-as-html", :account => recipient)

Implicitly

ActionMailer will automatically detect and use multipart templates, where each template is named after the name of the method, followed by the content type. Each such detected template will be added as a separate part to the message. For example:

    signup_notification.text.plain.erb
    signup_notification.text.html.erb
    signup_notification.text.xml.builder

Each would be rendered and added as a separate part to the message with the corresponding content type. The same body hash is passed to each template.