Dev-Box: Installing a Mail Server




Installing the mailing software is actually pretty easy, just run the below command and select the “No Configuration” option when asked how you want your server to be configured. We’ll take care of this ourself.

apt-get install dovecot-postfix


The configuration is where it gets kinda tricky. The way we are gonna set it up, all emails send by your server will be redirected to a single email address you define. In my case I’ll use an gmail account that all my the emails from my VM will be send to but in theory you could use any email account with any provider. So let’s get it started and I’ll explain further as we get along:

First we add a rule that makes sure all emails are redirected to a single email address. We do this by creating a new file called recipient_canonical_map

cd /etc/postfix
nano recipient_canonical_map

with this content


Once you saved the file we open up the postfix main config file


and enter this content

recipient_canonical_classes = envelope_recipient
recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_map

Now we can continue to the second part of the configuration where we make sure all the outgoings email are actually send and are send to your email address. We open up the file again


and add the following lines

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# information on enabling SSL in the smtp client.

myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination =
relayhost = []:587
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
default_transport = smtp
relay_transport = smtp
inet_protocols = all

# SASL Settings
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem

The SASL settings make sure that your server won’t be banned for spamming the mail account. Not sure if this works with other providers as well, only tested with Google Mail. To make the SASL part work we have to create a password file:

nano sasl_passwd

insert the following line (where you have to replace the email address and the password with your actual credentials)


Now we secure file and validate our certificate:

chmod 400 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
touch /etc/postfix/cacert.pem
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem >> /etc/postfix/cacert.pem

After restarting the mail server we are done and you can send an email from one of your apps and it should show up in your inbox of your gmail account:

/etc/init.d/postfix restart

I hope you like my mail server setup and it works for you :) I didn’t test this as extensive as I wanted to, but it works for me and so I hope it does for you! I’m looking forward to your comments and critique.

Leave a Reply

