Setting up SMTP server on a development test server running Ubuntu

This is a simple step-by-step tutorial to install and configure exim to route all e-mails send though a local SMTP server to one local user, regardless of the e-mail address or domain. I found this set-up very usefull when testing applications that send e-mail messages and you do not want to generate multiple HotMail accounts for testing or in case I'm wanted to do some testing and development when I'm offline.

Install exim

Start with installing exim.

user@devmachine:~$ sudo apt-get install exim4

Configure exim to handle desired domains

Next step is to confiure exim to treat a number of domains as local.

user@devmachine:~$ sudo dpkg-reconfigure exim4-config

Use the answers below and modify to suite your own needs.

General type of mail configuration
local delivery only; not on a network
System mail name<
enter hostname example devmachine
IP-addresses to listen on for incoming SMTP connections
127.0.0.1 ; ::1
Other destinations for which mail is accepted
devmachine; example.com; hotmail.com
Keep number of DNS-queries minimal (Dial-on-Demand)?
No
Delivery method for local mail
mbox format in /var/mail/
Split configuration into small files?
no
Mail for ‘postmaster’, ‘root’ and other system accounts needs to be redirected to the user account of the actual system administrator.
Leave empty we will take care of this below.

Configure catch all

So now we want to make sure all emails are routed to the same local user. Start by creating the file /etc/exim4/conf.d/router/950_exim4-config_catchall with this content.

1
2
3
4
catch_all:
   debug_print = "R: catch_all for $local_part@$domain"
   driver = redirect
   data = ${lookup{*}lsearch{/etc/aliases}}

Then add the following to /etc/aliases. Replace user with your local username.

1
*: user

Build new exim4 config and restart

1
2
3
4
5
user@devmachine:~$ sudo update-exim4.conf.template  -r
user@devmachine:~$ sudo update-exim4.conf
user@devmachine:~$ sudo service exim4 restart
 * Stopping MTA for restart                                                    [ OK ] 
 * Restarting MTA                                                              [ OK ]

Done!