Chances are that you don't want to turn your personal laptop into a full blown mailserver, however it is very important to set up a local only mailserver in linux. This allows you to receive errors from failed cronjobs along with other processes, and also is handy for development purposes.

# Installing sendmail

On Ubuntu simply enter

sudo apt-get install sendmail
sudo sendmailconfig


and answer yes to everything in the config.

Now you may see errors in syslog (and mail.err, mail.log) like "My unqualified host name (yourhostname) unknown; sleeping for retry". This is basically because your hostname, "yourhostname", is not a fully qualified domain name (FQDN) (e.g whoever@wherever.com). The solution is to edit /etc/hosts, to something like

127.0.0.1 localhost.localdomain localhost
127.0.1.1 yourhostname.localdomain yourhostname


This fixed the error for me anyhow. Check it with hostname -f

Now sendmail should be working.Trying sendmail -t lee from terminal. Type your message, press enter then finish with ".", finally press enter again. You should see mail in /var/mail/lee.

Note: you could at this point try sending my to a remote host, e.g. "someone@gmail.com", but if your on a laptop (not a VPS), chances are your ISP will block it. When I tried sendmail -vt someone@gmail.com < mail.txt, I got the error

 ... Deferred: Name server: gmail.com.: host name lookup failure


although if I connected to my VPN and tried exactly the same again, things worked. You can confirm that they're blocking the DNS MX record lookup by doing dig gmail.com MX; I got a time out when connected directly, but no problems when on the VPN. The mail will be sent to the gmail SPAM folder at any rate.

Next I want to set things up so that I can read mail in Thundberbird. Even though this is postfix, the same principles apply. Importantly, we want to be able to read mail to root as well, so we forward it to our user.

# Thunderbird

Mail in /var/mail is one thing, but it would be nice to be able to check these in Thunderbird. Even though this post is for postfix, the same principles apply.

1. First I update /etc/aliases

postmaster: root root: lee

so any mail directed to root comes to my user 'lee'. This allows me to monitor both root mail and lee's mail under one account. After making the changes, enter sudo newaliases.

2. Create the file /root/.forward containing just the entry lee@localhost (or whatever your user is called) so root's mail will come to you.

3. Next sudo adduser lee mail to add my user 'lee' to the mail group so Thunderbird can actually access the mail files.

4. Now in Thunderbird: "add other account", choose type "unix mailspool (movemail)" and enter your username and email address, e.g. "lee" and "lee@localhost.com"

5. Go to your new account in account settings, select server settings and select the local directory as /var/mail

6. Almost there! Configure the SMTP server: go to preferences>account settings then right to bottom in the left menu, click SMTP server and add a new one as follows:

Description: localhost servername: localhost port: 25 connection secuirty: none authentication: no authentication username localhost

In the account settings click on your newly created email address, "lee@localhost" and choose the newly created SMTP server from drop down.

You should now be able to send/receive mail to the inbox....try sending a mail to root@localhost, click Inbox and click "Get Mail"from the top-left. For some reason I always need to click "Get Mail" despite telling Thunderbird to check for new mail automatically every 5 minutes. I'm not quite sure why as Thunderbird auto polls all other emails correctly.

Currently unrated