Building a Test Email Server

Building a Test Email Server

Phill Luby
17th September 2025

Home Insights Building a Test Email Server

This post explains how to set up an email server on GNU/Linux that can be used for testing applications. It allows you to test that emails are correctly addressed (except for BCC) and allows you to receive the emails and view them in any POP3 email client just as if they’d been received normally.

These instructions assume Ubuntu 12.04 LTS, and that we are installing our SMTP and POP3 server on the same computer that is running our application, and that the application uses the local SMTP relay.

First, install postfix, which will be your SMTP server.

sudo apt-get install postfix

When asked what type choose local only, it doesn’t matter what you choose as a domain name.

Next, add the following line to /etc/postfix/main.cf:

virtual_alias_maps = regexp:/etc/postfix/virtual

This sets up our use of virtual alias maps which we’ll use to redirect all the mail in the next step.

Then create the file /etc/postfix/virtual and add the following line to it:

/.*/ mailsink

We’ll need a user creating for this mail dump account so run the following:

sudo adduser mailsink

Be sure to give it a reasonable password as this will be used to access emails later.

You may also wish to block spam if the server is public facing, in which case add the following line to /etc/postfix/main.cf

smtpd_recipient_restrictions = reject_rbl_client zen.spamhaus.org, reject_rbl_client bl.spamcop.net

Now we need a POP3 server installing:

sudo apt-get install dovecot-pop3d

The following command enables clear text authentication over POP3:

sudo sed --in-place "s|#disable_plaintext_auth = yes|disable_plaintext_auth = no|" /etc/dovecot/conf.d/10-auth.conf

The following command sets the mail_location in Dovecot:

sudo sed --in-place "s|#mail_location = |mail_location = mbox:~/mail:INBOX=/var/mail/%u|" /etc/dovecot/conf.d/10-mail.conf

The following command ensures that Dovecot has permission to delete emails from the inbox:

sudo sed --in-place "s|#mail_privileged_group =|mail_privileged_group = mail|" /etc/dovecot/conf.d/10-mail.conf

Some e-mail clients will require you to specify an out-going SMTP server too. To make this easier you can enable SMTP access to this server. However, this will allow junk mail to be delivered to the test mailbox so avoid it if you can. To enable SMTP access run the following command:

sudo sed --in-place "s|inet_interfaces = loopback-only|inet_interfaces = all|" /etc/postfix/main.cf

Any mail sent using this SMTP server it will be routed to the mailsink in-box.

If you are using UFW then enable POP3 access:

sudo ufw allow pop3
sudo ufw allow smtp

Now restart the affected services:

sudo service dovecot restart
sudo service postfix restart

You can now configure your email client to access the server using POP3, you should configure it to leave messages on the server so that you can test using different email clients. If the server is accessible over the internet then you can configure GMAIL and HotMail to access the mail using POP3.

Run the following command to send a test email (to verify that all email addresses get re-routed just use a real email address that you have access to, if this email doesn’t reach that address then everything is OK):

echo $'Subject: TEST\nHELLO\n.\n' | sendmail -t here@there.com
Share Article

Insights.

How to Run a Code Club
How to Run a Code Club

We’re hosting a Code Club community training evening to allow anyone who is thinking of becoming a Code Club volunteer an opportunity to find out more about Code Club and get an insight into what to expect and how to… 

Discover More
Building RaceBest
Building RaceBest

This year saw the launch of a new service from Leeds-based start-up RaceBest Ltd. NewRedo were responsible for building their online system and we continue to host and support it. In building the system we utilised some of the latest… 

Discover More
ASP.NET MVC on Ubuntu with NGINX
ASP.NET MVC on Ubuntu with NGINX

We’ve just published an early working version of an on-line service created by NewRedo, however, although written in ASP.NET MVC 2, it’s not running on a Microsoft server. Instead we’re running on Ubuntu 11.10 using the NGINX web server. First,… 

Discover More