Skip to content

allowing a rails app to send emails

cleesmith edited this page Mar 7, 2012 · 9 revisions

Sendmail as the delivery method

To allow a rails app to send emails a simple solution is to install the Postfix Mail Server, which allows rails to use the sendmail delivery method:

sudo aptitude install telnet postfix

When prompted, choose "Internet Site" and leave the system mail name at the default.

Now, to ensure Postfix and Sendmail are working do:

/usr/sbin/sendmail your_email_account@gmail.com
FROM: me
SUBJECT: hi
this is only a test
. <press Enter twice>

Then check your inbox for the email.

Once the server can send emails edit config/environments/production.rb:

nano config/environments/production.rb

and add the following lines, by default these lines are included, but the :host should be changed to match the server:

config.action_mailer.delivery_method = :sendmail
config.action_mailer.default_url_options = { :host => "somedomain.com" }

SMTP as the delivery method

It is also possible for rails to send emails using the SMTP delivery method, and for more details please refer to the Rails Guides.


Emails, Redis, and Resque Mailer

If Redis has been installed and is running, this rails app will process any emails sent in the background using Resque Mailer which is a more efficient way to handle emails. If the rails app can not detect Redis it will send emails as normal in the foreground.