Quit your mail server admin job. Now!
Why a small team should reconsider running its own mail infrastructure.
- Published
- Reading time
- 5 min read
This article outlines the problems I encountered while running a mail server and describes the pragmatic Google Apps alternative I chose in 2009.
The mail server problem
Managing a server is not necessarily difficult when you understand the system, but it always consumes time. That cost is a reason to reconsider managing every service yourself.
I like controlling my servers and knowing that I can change them whenever necessary. That preference led me to run my own mail server. Once Postfix supported virtual users, adding an account appeared to require only one more row in a MySQL table.
1. Unexpected downtime
One afternoon, part of the system stopped working. I had to abandon my other work and diagnose the problem manually. The mail server remained unavailable for five hours. Email tolerates temporary delivery failures reasonably well, but an important message could still have been delayed or lost during that window.
2. Mail account management
The startup had three core team members, but I was the only person who knew how to add an account to the MySQL mail-users table. While I was away for a week, nobody else could create an account for an intern. A supposedly simple administrative task had become dependent on one person.
3. Reliable mailing for your application
Most web applications need reliable communication with their users, and email remains a common channel. A mail-server outage can also break registration, password resets, and notifications.
A mail-server misconfiguration once broke user registration for about eight hours. That window was small compared with a year of operation, but exception reports indicated that it affected roughly six people. A first interaction that fails can permanently damage a user’s trust in a service.
What you really want
- The team needs to send and receive email.
- The service must remain reliable throughout the year because communication failures have business consequences.
- The application needs to send transactional email.
- Nontechnical colleagues should be able to manage accounts.
- Users should have webmail without requiring the team to maintain its infrastructure.
- The service should reduce both direct costs and administrative time.
What you could do to avoid emails completely
An application could avoid some email by using Twitter for OAuth authentication, messages, and notifications. In 2009, libraries such as the twitter gem and Twitter4R made that idea easy to explore. I would have welcomed fewer automated messages in my inbox.
This article still focuses on email because the application continued to depend on it.
What I did as a first step
As a startup, PaperC needed to control infrastructure costs. We rented servers for the core platform but outsourced services that did not differentiate the product. Our email volume was still modest, so we chose Google Apps for mail delivery. The service fit our needs at the time, with a professional mail host such as Rackspace remaining an option for future growth.
How to integrate Google Apps into your rails app
Google Apps suited only smaller applications because each account had a daily sending limit. Before adopting it, estimate the application’s delivery volume and choose a professional provider if the limit is too restrictive. At the time of writing, Google documented these limits per account:1
- Standard Edition allowed 500 external recipients per day.
- Premier and Education Edition allowed 2,000 external recipients per day.
The email addresses can be distributed among the To:, Cc:, and Bcc: fields.
2. Set up a mail account from which the server can send messages.
3. Follow Google’s instructions to update the MX records for the domain.
4. Add an SPF record to reduce the risk of outgoing messages being classified as spam.
The SPF Setup Wizard can create the record, and the SPF Query Tool can validate it.
5. Edit config/environments/production.rb as follows.
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:domain => "yourdomain.com",
:address => "smtp.googlemail.com",
:tls => true,
:authentication => :plain,
:user_name => "[email protected]",
:password => "yourpassword"
}6. Install and apply the simple-tls gem with the following commands.
$ sudo gem install ambethia-smtp-tls -shttp://gems.github.com# in config/environment.rb
config.gem 'ambethia-smtp-tls', :lib => 'smtp-tls', :version => '1.1.2', :source => 'http://gems.github.com'7. Deploy and relax.
After deployment, monitor the mail volume regularly and upgrade the account or provider before reaching the documented limits.