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.

ActionMailer::Base Configuration Methods

ActionMailer is configured by acessing configuration methods at the class level, for example, ActionMailer::Base.template_root = "/my/templates". These methods allow you to define the overall settings to be used by your application whenever it invokes ActionMailer. Define these settings in your config/environment.rb file using config.action_mailer.method_name_here. If you require different settings for each of your Rails' environments, define settings separately via config/environments.

smtp_settings = {hash}

:address - the address of the SMTP server you will be using to send email. Defaults to localhost

:port - the port number of the SMTP server you will be using. Defaults to 25

:domain - if you need to specify a HELO domain, you can do it here

:user_name - if your mail server requires authentication, set the username in this variable

:password - if your mail server requires authentication, set the password in this variable

:authentication - if your mail server requires authentication, you need to specify the authentication type here. This is a symbol, and one of :plain, :login, or :cram_md5

sendmail_settings = {hash}

:location - the location of the sendmail executable, defaults to /usr/sbin/sendmail :arguments - the command line arguments for sendmail

raise_delivery_errors = true or false

Whether or not errors should be raised if the email fails to be delivered.

delivery_method = :smtp, :sendmail or :test

Defines a delivery method, defaults to :smtp

perform_deliveries = true or false

Determines whether deliver_* methods are actually carried out. By default they are, but this can be turned off to help functional testing.

template_root = "/path"

The root from which template references will be made

logger

Used for generation information on the mailing run if available. Can be set to nil for no logging. Compatible with Ruby's own Logger and Log4r loggers.

default_charset = "string"

the default charset used for the body and to encode the subject. Defaults to UTF-8. You can also pick a different charset from inside a mailer method by setting charset

default_mime_version = "string"

The default mime version used for the message. Defaults to 1.0. You can also pick a different value from inside a mailer method by setting mime_version

default_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. You can also pick a different value from inside a mailer method by setting implicit_parts_order

default_content_type = "string"

The default content type used for the main part of the message. Defaults to text/plain. You can also pick a different value from inside a mailer method by setting content_type