Setup Mail Sending

This guide will setup a fundamental server necessary, among others, for password recovery and tasks notifications, which is the email server. See also SettingEnvironmentContactEmail for proper sender address setup.

Testing your configuration

On the server production console run:
ActionMailer::Base.logger =
class Sender < ActionMailer::Base                                                                                                     
  def test(to, from=Environment.default.noreply_email)
    mail to: to, from: from,
      subject: "test", body: 'test'

To just test your local email server, run:

echo "Test mail from postfix" | mail -s "Test Postfix"

Or under telnet localhost 25

HELO localhost
Type message here.


Go to and run the diagnostics on your domain. For email servers to accept your emails or don't mark emails as spam, it should pass on all tests.

Development setup

Rails 2 doesn't support sending mails to local files. So add support for it with:
gem install specific_install
gem specific_install -l git://

Then add to config/local.rb

require 'rubygems'
require 'letter_opener'
ActionMailer::Base.delivery_method = :letter_opener
ActionMailer::Base.custom_letter_opener_mailer = => Rails.root.join("tmp", "mails"))

See this for more details.


Exim4 (MTA)

Just install exim4:
sudo apt-get install exim4-daemon-light mailutils
Configure exim4 for Local Mail Service
dpkg-reconfigure exim4-config
At configuration helper,

(1st screen) choose the option for "internet site" and select "Ok" to continue.

(2nd screen) Enter your system's FQDN (fully qualified domain name) on the "mail name" configuration screen.

(3rd screen) Enter "" when asked which IP address to listen on for SMTP connections.

(4th screen) Make sure you list your FQDN, hostname, and localhost entries when you're asked which destinations mail should be accepted for. i.e.:; myserver; localhost.localdomain; localhost

(5th & 6th screens) Leave the relay domains and relay machines fields blank. (except if you what you're doing)

(7th screen) Select "No" when asked whether to keep DNS queries to a minimum.

(8th screen) You may select either "mbox" or "Maildir" when asked about the delivery method used for incoming mail. While many utilities use mbox format, Maildir format can make handling individual locally delivered mail messages easier, and is widely supporting by a range of applications.

(9th screen) Accept the default "non-split" option for your mail configuration file.

Test your mail configuration. Issue the following command to send a test email, substituting an external email address for

echo "This is a test." | mail -s Testing

And make sure config/local.rb file is empty.

Postfix (MTA)

Install postfix
sudo apt-get install postfix

Open /etc/postfix/ and pay attention to the mynetworks, myhostname and mydestinations, as they are very important to avoid email rejection.

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination =, localhost.localdomain, localhost
relayhost = 
mynetworks = [::ffff:]/104 [::1]/128 yournetworkip/32
mailbox_size_limit = 0 
recipient_delimiter = + 
inet_interfaces = all 
virtual_maps = hash:/etc/postfix/virtusertable

See for more details.


You can use a local sendmail server to send emails. Note that may be dificult for emails servers to accept these emails sent by sendmail using an internet IP address.

Add to config/local.rb:

ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.sendmail_settings = {
    :location       => '/usr/sbin/sendmail',
    :arguments      => '-i -t'

SMTP without security layer

Add to config/local.rb:
ActionMailer::Base.smtp_settings = {
  :address => "",
  :port => "587",
  :domain => "",
  :authentication => :plain,
  :user_name => "USERNAME",
  :password => "PASSWORD"

Note that the plugin showed below may conflict. You may uninstall it by just removing its directory.

TLS based server

Let's setup using a Google Account and GMail SMTP server, although this guide should work on any TLS based SMTP server. It was based on Douglas F Shearer's guide

You'll need to install a plugin for TLS support. Just run:

script/plugin install git://

Add to config/local.rb:

ActionMailer::Base.smtp_settings = {
    :tls => true,
    :address => "",
    :port => "587",
    :domain => "YOURDOMAIN",
    :authentication => :plain,
    :user_name => "GOOGLEUSERNAME",
    :password => "GOOGLEPASSWORD"

Add comment
You need to login to be able to comment.
Topic revision: r18 - 27 Sep 2014 - 18:47:06 - BraulioBhavamitraBO

irc Talk with Devs Now!

Translations: English
Search on Docs:
ActionItem Search:

Copyright © 2007-2015 by the Noosfero contributors
Colivre - Cooperativa de Tecnologias Livres