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!

60 Comments

  • Preview
Markdown Preview
  • B
  • I
  • H1
  • H2
  • H3
  • UL
  • OL
  • Code
  • Highlight
  • Table
  • 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.

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

    • 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.

    • Thanks, looks good!
      I was looking for something that is innovative. I found a mailserver written in node! I tested it and it was nice but it has a few serious issues and limitations.
      Anyway tried and tested is good. At least I don’t have to spend a week studying arcane configuration files.

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

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

    • 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!

    • 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.

    • ikr I also want to run my own mail server would love it though!

  • 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.

  • 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.

  • 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.

  • 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.

  • 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

  • This is not a tutorial.

  • “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.

  • 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.

  • 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

    • 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.

  • 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.

    • 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.

  • 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.

  • 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…

  • 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 :)

  • 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.

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

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

    • Thanks for share that fantastic alternative! The service is really awesome. It can handle more than one email in same account, even alias is possible.

  • @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.

    • If you are happy running your own mail server, that’s great! :)

    • This article is clearly a marketing lie. If you own a VPS (wherever it is), you have the tech skills to set up your own mail server.

      • You might consider that it’s not necessary a tech skill issue but more of a time / requirement / business issue. I have the tech skills and the will to set up a mail server and I did it. My problem lies with users and time. Some of my users expect webmail - I choose not to provide that due to resources/security concerns. For them and others I chose to use alternatives.

        E-mail server configuration can be a pain, especially if you want to do a good job and not just to “have it there and work”. And speaking of good job, that actually does not have a time limit - you can spend forever on a project and still not have it “perfectly” configured, where perfectly would include both mission critical/functional and for fun/nice to have requirements.

Previous 1 2 Next
Creative Commons License

We use cookies to provide our services and for analytics and marketing. To find out more about our use of cookies, please see our Privacy Policy. By continuing to browse our website, you agree to our use of cookies.