How to setup a local SMTP mail server for testing tools

Running a local mail server can be extremely useful for testing tools that offer mailing functionality. For example, before using GoPhish (or any software that offers email functionality) on an engagement, an operator may have to test the tools locally to investigate the behavior of the tool and get an understanding of potential pitfals. This post describes the steps to install and configure all the required software packages for a local SMTP server.

The post is split in the following sections:

Install and configure Unbound DNS resolver

Unbound [2] is an awesome project that is actually more than a DNS resolver. However, in this post it is only used as a DNS resolver and more specifically, to override internet zones.

Effectively, Unbound DNS is used for two reasons: a) to avoid changing the hostname of the host the SMTP is running on and b) to make a - as much as possible - real environment by using a valid internet domain that will resolve to (localhost).

To install Postfix:

sudo apt install unbound

Pick a valid domain to mimic a valid email address, such as

To make point to localhost ( unbound is used to configure override settings. Edit /etc/unbound/unbound.conf and append the following configuration:

	local-zone: "" static
	local-data: " IN A"
	local-data: " IN A"
	local-data: " IN MX 10"
	local-data-ptr: ""

If on a Debian distro and NetworkManager is managing the network configuration, it is required to change the DNS settings and set a static DNS at This will ensure all the queries are directed to the unbound DNS server.

To set a static DNS server, edit the file /etc/NetworkManager/system-connections/<REPLACE_WITH_THE_NAME_OF_THE_CONNECTION> (for example /etc/NetworkManager/system-connections/Wired connection 1) and add the following settings at the IPv4 section of the configuration file:


After the change restart the unbound service and NetworkManager by issuing the command systemctl restart unbound and systemctl restart NetworkManager (depending the operating system, the command to restart network manager may vary).

To confirm that the DNS server is now, resolve by issuing a command like:

dig a +short

If the response is:, this means that the zone has been successfully overridden. Likewise, any internet domain can be overridden to resolve to a custom IP address.

Install and configure Postfix mail server

Postfix is both great and complicated enough piece of software that offers mailing server functionality. To install it:

sudo apt install postfix

Thankfully, not much configuration is required if configuring Postfix to function as a local only SMTP server.

During installation, Postfix will ask how it will be configured in the dialog box “General type of mail configuration”. Simply select “Local Only” and proceed to the next steps without changing the default options (if any).

The next step is to configure a “catch all” address - an email address that catches all the coming in messages and delivers them to a valid user on the host. For example, a mail that is sent to will be delivere to if a catch-all address has been configured for the user account a.user. So, a user account is required.

To enable the above functionality, create the file /etc/postfix/virtual and include the following (it is assumed the domain and the a.user are used - replace them accordingly if interested in configuring different accounts):

@example a.user a.user

To instruct postfix to enable this functionality, edit /etc/postfix/ and append the line:

virtual_alias_maps = hash:/etc/postfix/virtual

Update the Postfix lookup table by:

sudo postmap /etc/postfix/virtual

Restart the postfix service to load the new configuration:

sudo systemctl restart postfix

The Postfix server should be up and running! If the Postfix service does not load upon every boot, do systemctl enable postfix.

Access emails with Evolution mail client

To retrieve (read) emails from the local SMTP server, a mail client that offers the option to read and store emails to spool files is required. Evolution mail client (available on Debian and other distributions) checks the box.

To configure the account navigate to Edit -> Preferences -> (left side) Mail Accounts -> (right side) Add.

Identity tab:

Receiving E-mail tab:

Receiving Options tab:

Sending E-mail tab:

Account Summary tab:

At this point, anyone should be able to send an email to any email address The emails are delivered to


A special thanks to:







tags: #random