Every now and then my paranoia will take over and I’ll have an urge to break free of all 3rd parties that I depend on for my life on the internet. The last time it struck I decided to set up my own mail server. I’m going to walk you through what I did in order to get it working

Important Acronym List (IAL)

Mail Transfer Agent: MTA This is the piece of software that handles incoming AND outgoing email. It receives email and then decides whether or not the message is for one of the users it knows about. It also decides who gets to send email and handles the delivery. In this tutorial we’re going to be using Postfix. The primary protocol that it speaks is SMTP

Internet Message Access Protocol: IMAP By default, postfix will deliver email messages to a folder on the computer it’s running on and the only way to access the messages is when you are logged into that box. Since this is kind of impractical, there are a ton of protocols that have been created to make accessing email messages on a remote server easy. We’re going to use dovecot and IMAP (the protocol) to access our messages on the server. You can also get dovecot to work with POP3, but this guide doesn’t cover getting it set up since it’s an older and less useful protocol.

What you need

  • A domain
  • I use namecheap, but I hear good things about
  • A server
  • Preferably running debian or ubuntu. It will be helpful for preventing your mail from being marked as spam if you can set the PTR / reverse DNS for this server’s IP address. Sadly, this means that you probably can’t run this on a server you have in your house. If you need a server, I recommend BuyVM since they have a $15 a year VPS that is perfectly adequate for this purpose.
  • An SSL certificate
  • You can get one for free from StartSSL


We’re mostly going to follow along with this guide from linode except for the bits about MySQL [1]. I don’t understand why they would use MySQL here since it’s huge overkill unless you are dealing with a very large number of users. Instead of MySQL we’re going to use sqlite since it doesn’t require any processes to be running and eating up the limited RAM available on the VPS.

You should follow the linode guide, except when they start talking about MySQL in which case you should come back here and see how to do it with SQLite. I’ve tried to match up the section/numbering so that it’s easy to figure out what to do differently.

Installing Packages

Step 3

Install these packages instead: sudo apt-get install postfix postfix-mysql dovecot-core dovecot-imapd dovecot-lmtpd dovecot-sqlite sqlite

Step 4 and 5


SQLite instead of MySQL

Creating the database

Download this empty mailbox.sqlite and put it in /etc/mailbox.sqlite or if you don’t trust me you can create you’re own with this schema:

This will create our tables

Adding data

You can add data to sqlite database with the same syntax as MySQL, but interact with the database using the sqlite or sqlite3 command instead of mysql


Step 8

Use the following instead of the one in the guide

We’ll be using these file names later as well

Step 11

Use this instead: nano /etc/postfix/

Step 12

Step 15

You can test the set up by referencing your sqlite file instead of the mysql one. eg: postmap -q sqlite:/etc/postfix/

Step 16

Use this instead: nano /etc/postfix/

Step 17

Step 20

Test with: postmap -q sqlite:/etc/postfix/

Step 21

Use this instead: nano /etc/postfix/

Step 22

Step 25

Test with: postmap -q sqlite:/etc/postfix/ (You get the idea at this point I hope)

Step 28

I skipped this bit entirely without any ill effects


Step 25 to Step 28

Please use the following as the contents of dovecot-sql.conf.ext


If all went well then you should be able to connect successfully to your new email server with your email client to both receive and send email! It’s amazing, I know.

In the next installment I’ll walk through the process of signing your email with DKIM so that it won’t get marked as spam by pretty much every email provider in existence



[1] I would have liked to reproduce most of the guide here since it IS published under a creative commons license, but it specifies no derivatives so I can’t actually modify it at all...