manicas
Dec 11, 2014
HeartedHeart
39
37
We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

Why You May Not Want To Run Your Own Mail Server

Tags: Email

Introduction

When setting up a web site or application under your own domain, it is likely that you will also want a mail server to handle the domain's incoming and outgoing email. While it is possible to run your own mail server, it is often not the best option for a variety of reasons. This guide will cover many of the reasons that you may not want to run your own mail server, and offer a few alternatives.

If you do not want to read the entire article, here is a quick summary: setting up and maintaining your own mail server is complicated and time-consuming, and there are several affordable alternatives—most people will get more value, in the form of saved time, out of using a paid mail service. With that said, read on if you want more details.

Mail Servers Are Complex

A typical mail server consists of many software components that provide a specific function. Each component must be configured and tuned to work nicely together and provide a fully-functioning mail server. Because they have so many moving parts, mail servers can become complex and difficult to set up.

Here is a list of required components in a mail server:

  • Mail Transfer Agent
  • Mail Delivery Agent
  • IMAP and/or POP3 Server

In addition to the the required components, you will probably want to add these components:

  • Spam Filter
  • AntiVirus
  • Webmail

While some software packages include the functionality of multiple components, the choice of each component is often left up to you. In addition to the software components, mail servers need a domain name, the appropriate DNS records, and an SSL certificate.

Let's take a look at each component in more detail.

Mail Transfer Agent

A Mail Transfer Agent (MTA), which handles Simple Mail Transfer Protocol (SMTP) traffic, has two responsibilities:

  1. To send mail from your users to an external MTA (another mail server)
  2. To receive mail from an external MTA

Examples of MTA software: Postfix, Exim, and Sendmail.

Mail Delivery Agent

A Mail Delivery Agent (MDA), which is sometimes referred to as the Local Delivery Agent (LDA), retrieves mail from a MTA and places it in the appropriate mail user's mailbox.

There are a variety of mailbox formats, such as mbox and Maildir. Each MDA supports specific mailbox formats. The choice of mailbox format determines how the messages are actually stored on the mail server which, in turn, affects disk usage and mailbox access performance.

Examples of MDA software: Postfix and Dovecot.

IMAP and/or POP3 Server

IMAP and POP3 are protocols that are used by mail clients, i.e. any software that is used to read email, for mail retrieval. Each protocol has its own intricacies but we will highlight some key differences here.

IMAP is the more complex protocol that allows, among other things, multiple clients to connect to an individual mailbox simultaneously. The email messages are copied to the client, and the original message is left on the mail server.

POP3 is simpler, and moves email messages to the mail client's computer, typically the user's local computer, by default.

Examples of software that provide IMAP and/or POP3 server functionality: Courier, Dovecot, Zimbra.

Spam Filter

The purpose of a spam filter is to reduce the amount of incoming spam, or junk mail, that reaches user's mailboxes. Spam filters accomplish this by applying spam detection rules--which consider a variety of factors such as the server that sent the message, the message content, and so forth--to incoming mail. If a message's "spam level" reaches a certain threshold, it is marked and treated as spam.

Spam filters can also be applied to outgoing mail. This can be useful if a user's mail account is compromised, to reduce the amount of spam that can be sent using your mail server.

SpamAssassin is a popular open source spam filter.

Antivirus

Antivirus is used to detect viruses, trojans, malware, and other threats in incoming and outgoing mail. ClamAV is a popular open source antivirus engine.

Webmail

Many users expect their email service to provide webmail access. Webmail, in the context of running a mail server, is basically mail client that can be accessed by users via a web browser--Gmail is probably the most well-known example of this. The webmail component, which requires a web server such as Nginx or Apache, can run on the mail server itself.

Examples of software that provide webmail functionality: Roundcube and Citadel.

Maintenance is Time-Consuming

Now that you are familiar with the mail server components that you have to install and configure, let's look at why maintenance can become overly time-consuming. There are the obvious maintenance tasks, such as continuously keeping your antivirus and spam filtering rules, and all of the mail server components up to date, but there are some other things you might have not thought of.

Staying Off Blacklists

Another challenge with maintaining a mail server is keeping your server off of the various blacklists, also known as DNSBL, blocklists, or blackhole lists. These lists contain the IP addresses of mail servers that were reported to send spam or junk mail (or for having improperly configured DNS records). Many mail servers subscribe to one or more of these blacklists, and filter incoming messages based on whether the mail server that sent the messages is on the list(s). If your mail server gets listed, your outgoing messages may be filtered and discarded before they reach their intended recipients.

If your mail server gets blacklisted, it is often possible to get it unlisted (or removed from the blacklist). You will want to determine the reason for being blacklisted, and resolve the issue. After this, you will want to look up the blacklist removal process for the particular list that your mail server is on, and follow it.

Troubleshooting is Difficult

Although most people use email every day, it is easy to overlook the fact that it is a complex system can be difficult to troubleshoot. For example, if your sent messages are not being received, where do you start to resolve the issue? The issue could be caused by a misconfiguration in one of the many mail server components, such as a poorly tuned outgoing spam filter, or by an external problem, such as being on a blacklist.

Easy Alternatives — Mail Services

Now that you know why you probably do not want to run your own mail server, here are some alternatives. These mail services will probably meet your needs, and will allow you and your applications to send and receive email from your own domain.

This list doesn't include every mail service; there are many out there, each with their own features and prices. Be sure to choose the one that has the features that you need, at a price that you want.

Easy Alternatives — Postfix for Outgoing Mail

If you simply need to send outgoing mail from an application on your server, you don't need to set up a complete mail server. You can set up a simple Mail Transfer Agent (MTA) such as Postfix. A tutorial that covers this can be found here: How To Install and Setup Postfix on Ubuntu 14.04.

You then can configure your application to use sendmail, on your server, as the mail transport for its outgoing messages.

Not Convinced?

If you really want to run your own mail server, we have a few tutorials on the topic. Here are links to a few different setups:

Good luck!

37 Comments

Markdown Preview
  • B
  • I
  • H1
  • H2
  • H3
  • UL
  • OL
  • Code
  • Highlight
  • Table
  • Preview
Could not load preview. Try again
Loading preview...
    JoshData

    There is also https://mailinabox.email/, a project I started to deploy a working mail server without the need (or even the possibility) to configure the system. It's like an email appliance. It doesn't solve all of the issues of running your own mail server, but it does solve a lot.

    HeartedHeart
    4
    Reply
      finid

      What is the minimum RAM required for your project to run, and do you have any intention of building a containerized version?

      HeartedHeart
      Reply
      JoshData

      The recommendation is 768M. A containerized version would be nice, but I couldn't get Docker to work and no one is working on it now as far as I know.

      HeartedHeart
      Reply
    nardus

    Would have thought that zoho.com deserved a mention at least.
    And Outlook.com haven't offered service for custom domains for a while...

    HeartedHeart
    1
    Reply
    k0nsl

    I run my own mail server(s) without any issues and whenever there's an issue, it's just "fun" to fix it :]

    HeartedHeart
    6
    Reply
      Tecca

      I agree! I ran into a few problems during set up, but after it was all said and done, the experience was great. I learned a lot during the process and continue to learn every day. My mail server has been up and running successfully, without any issues, for nearly a year now. No regrets!

      HeartedHeart
      4
      Reply
      nathanosman

      I run my own mail server as well, and I agree - it is a challenge to configure properly. Getting Postfix and Dovecot talking to each other is a bit easier on Ubuntu thanks to the mail-stack-delivery package. I installed Roundcube in order to provide webmail access to other users, though I use IMAP myself.

      Actually, the two most difficult aspects of setting things up was getting SpamAssassin configured correctly and getting the Thunderbird email client to use the correct IMAP/SMTP settings.

      HeartedHeart
      2
      Reply
    metaprinter

    How do I go about adding my Exchange Online MX record? I only see an option for gmail MX record?

    EDIT
    Figured this out from an older comment thread. For anyone else doing this, in the MX hostname enter the Office 365 mail server with a dot at the end and set the priority to 0.

    HeartedHeart
    Reply
    phillh

    I run about 10 domains on a single $5 Ubuntu box on DO with Zpanel http://www.zpanelcp.com and so far no issues. I just do forwards with this which is super easy to setup and works well, never had any issues.

    HeartedHeart
    1
    Reply
    geggleton

    I am going to have to disagree. You can easily run your own mail-server, I do it for 150 people at work and yeah I am the solo IT guy. I spend 1 minute a day on average just making sure there's nothing funky in log files...

    There is however a giant learning curve. If you aren't afraid of learning how email works then you have no problem at all. There are plenty of tutorials to follow. Also running your own mail server is the only scalable option... places that do hosted email often are $2/mailbox... for 150 that is $300/mo... Our server runs off of a $20 instance... Huge cost savings for a bit of work.

    HeartedHeart
    3
    Reply
    reckless2k2

    I ran a Zimbra mail server a while back with fail2ban preventing attacks but I still got hacked. Just didn't seem worth the trouble. Turned it over to Google while you could still do free and have been good with that.

    HeartedHeart
    Reply
    skydriver

    I'm using iRedMail as mailserver soulution and i'm pretty satisfied with it. Of couse, hosting your own mailserver is nothing for you if you do not have any idea how to handle it. But you can say this for everthing.
    I can also write an acticle thats called "Why You Should Not Run Your Own Web Server" or "Why You Should Not Run Your Own XYZ Server".

    If you let anything do others for you, you'll learn absolutly nothing, and in my option thats the wrong way. Digital Ocean brings you a perfect platform to do what you want, try things out, and if it's not working .. jump back to a clean, fresh installed system, reachable from all over the world, and not only in your private home network.

    So, thanks, Mitchell, for your tutorial, but please all of you try things out and learn how it works!

    j2c
    skydriver

    HeartedHeart
    Reply
    andrew782304

    This is not a tutorial.

    HeartedHeart
    6
    Reply
    fidseceu

    "Mail Servers Are Complex
    A typical mail server consists of many software components that provide a specific function."
    Use iRedMail. If you can't configure by yourself, iRedMail will do it for you. All you need is clean Ubuntu or another OS. Just run install script and reboot.

    HeartedHeart
    Reply
    tekkenmaster

    I disagree with you for this, it depends on your level of knowledge and experience running the show plus you must have enough resources to host the platform. I deployed multi-tenant Exchange Servers 2010 and 2013 without any issues having regional offices in one country.

    HeartedHeart
    Reply
    Jkirkby

    I've used alot of your tutorials and usually love them, but with this i highly disagree, how about why telling people why they shouldn't be using centralised services like gmail and why they should be using their own mail server

    HeartedHeart
    1
    Reply
      asb

      Maybe that will be our next tutorial. =) The title is a bit tongue-in-cheek. It's really just aiming to give people some insight to the complexities involved with running a mail server. Unfortunately, a lot of folks don't understand what they're in for when they set off on the task.

      HeartedHeart
      1
      Reply
    markharrisberry

    Hi,

    If I don't install the mail server, how do I get the magento to send email to customer once a transaction is made.

    HeartedHeart
    Reply
      kamaln7

      Hi,

      This tutorial talks about running a mail serve that is used to receive email (e.g. instead of Gmail, Outlook, or other similar services). You will need to install an MTA such as postfix to send email from your application/Magento. Just make sure that it's listening on the loopback interface (127.0.0.1) and you should be OK.

      If you're using postfix, edit /etc/postfix/main.cf and set inet_interfaces = loopback-only. Don't forget to restart postfix so that the changes take effect:

      sudo service postfix restart
      

      You can find what interface your mail server is listening on by running the following command:

      sudo netstat -plutn | grep 25
      

      The output should look like this:

      tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2855/postfix
      

      If the part in red is 127.0.0.1 or 127.0.1.1, then it's listening on the loopback interface.

      HeartedHeart
      Reply
    santiagogonzalez2002

    MandrillApp is a great alternative if you dont want to install a mailserver on your droplet. They offer a free plan wich allows you to send 12.000 per month. I have been using it for 6 months and it works just great :) Give it a try.

    You just need to sign app for free, get an api key and set up your application to use mandrill smtp. In just 5 minutes you are up and running.

    HeartedHeart
    1
    Reply
    redviam

    After trying it out for myself and reading this article, I couldn't agree more. Yes, it might be fun and so on, but if you're not doing it seriously (company, emplayees etc). Otherwise I would strongly recommend using already built and managed systems, because it can get a mess and very sensitive data can be lost, corrupted.
    And actually after checking service providers, prices and options, simply I can't find any other solution than going back to godaddy, because it just beats the price and offers. Although I hate service and that I can't have my hands on everything as I could on DO, but...

    HeartedHeart
    2
    Reply
    theodis

    I'd rather spend up to $20 for two highly available mail servers for per month than to pay $3 or $5 per mailbox and be limited on storage space.

    All it took was Godaddy and Hostgator going down once last year for me to decide to run my own sites, databases, and email for myself and my customers on Digital Ocean and another cloud provider.

    And don't get me started on my PBX :)

    HeartedHeart
    Reply
    johnryanpowell

    I totally agree. I tried hosting my own and it was actually fairly simple to set up. It was great for a few months and then there was a problem. Luckily I was able to fix that in a few hours. Then six months later a problem popped up that I couldn't google a fix for since I the only error I was getting was that email wasn't coming through and it wasn't going out either. Digging through logs didn't provide any info either.

    So I gave up and switched to fastmail. I made the mistake of hosting my own for work related stuff so I have no clue how much money I lost while my email was out. It was a good learning experience and if I did it again I would just use it for shopping and family/facebook stuff.

    HeartedHeart
    1
    Reply
    stoutflores

    We are using Microsoft Office365 they have a very good customer support service.

    HeartedHeart
    Reply
    nab

    Russian Yandex is also good alternative for self hosted mail. Unlike Google they still have free plans.

    HeartedHeart
    Reply
    shmoo

    @mitchel: While it's true that running your own mail server isn't easy and that it is time consuming, I am still not convinced that I shouldn't be doing it. Having my own mail server is as important as hot water. Free mail service isn't really free-- you lose your privacy, control of who can and can't contact you.
    So it's my impression that you don't run your own mail server and/or you believe that you have nothing to hide and the spooks are welcome to sift through your mail.

    HeartedHeart
    Reply
Previous 1 2 Next
Creative Commons License