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 = Logger.new(STDOUT)
class Sender < ActionMailer::Base                                                                                                     
  def mail(to)
    recipients to
    from Environment.default.contact_email 
    reply_to Environment.default.contact_email
    subject "test"
    body render(:text => 'test')
  end
end
Sender.deliver_mail('youremail@domain.com')

To just test your local email server, run:

echo "Test mail from postfix" | mail -s "Test Postfix" admin@something.com

Or under telnet localhost 25

HELO localhost
MAIL FROM: noreply@noosfero.net
RCPT TO: youremail@domain.com
DATA
Type message here.
.
QUIT

Diagnostics

Go to http://mxtoolbox.com/diagnostic.aspx 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://github.com/cavi21/letter_opener.git

Then add to config/local.rb

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

See this for more details.

Servers

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 "127.0.0.1" 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.example.com; 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 someone@somedomain.com.

echo "This is a test." | mail -s Testing someone@somedomain.com

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

Postfix (MTA)

Install postfix
sudo apt-get install postfix

Open /etc/postfix/main.cf 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_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
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 = yourdomain.net
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = yourdomain.net, localhost.localdomain, localhost
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 yournetworkip/32
mailbox_size_limit = 0 
recipient_delimiter = + 
inet_interfaces = all 
virtual_maps = hash:/etc/postfix/virtusertable

See http://www.postfix.org/BASIC_CONFIGURATION_README.html for more details.

Sendmail

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 => "mail.mydomain.com",
  :port => "587",
  :domain => "mydomain.com",
  :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://github.com/collectiveidea/action_mailer_optional_tls.git

Add to config/local.rb:

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

Add comment
You need to login to be able to comment.
 
Topic revision: r16 - 11 Jan 2014 - 20:38:52 - BraulioBhavamitraBO

irc Talk with Devs Now!

 
Translations: English
Search on Docs:
   
ActionItem Search:

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