Hack and / - Make a Local Mutt Mail Server

Mail server configuration doesn't have to require pages of text files, five manuals and a team of system administrators. If you just need to relay mail from your local mutt client, it'll take a few minutes and a few short lines in a Postfix config.

to your /etc/postfix/main.cf. Replace mail.somedomain.net with the hostname of your ISP's relay host. Once you modify the file, simply type postfix reload as the root user to enable the new settings.


Of course, some mail servers won't just let anyone on their network relay through them (and rightly so). In that case, usually they require that everyone authenticate with them first. This takes a few extra steps with Postfix, but like with everything else, it's still not very difficult. First, add the following lines to the /etc/postfix/main.cf:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

This tells postfix to enable SMTP authentication and tells it to look in /etc/postfix/sasl_passwd for logins and passwords to use for hosts. The next step is to create the /etc/postfix/sasl_passwd file. If I wanted to log in to mail.somedomain.net with the user name kyle and the password muttrules, I would put the following line in the file:

mail.somedomain.net kyle:muttrules

There is a downside to this in that the password for the account is now in clear text. That's less than ideal, but you can at least make sure that only root can read the file. As the root user, type:

# chown root:root /etc/postfix/sasl_password
# chmod 600 /etc/postfix/sasl_passwd

Postfix actually doesn't read this file directly; instead, it reads a hash database created from this file. To create the file, run:

# postmap /etc/postfix/sasl_passwd

And, you will see that a new file, /etc/postfix/sasl_passwd.db, has been created. You'll need to run the postmap command any time you modify the /etc/postfix/sasl_passwd file. Now, reload Postfix one final time, and mutt should be able to relay mail through your local host. If you want to perform a quick test without mutt, you can type:

echo test | mail -s "test" user@remotehost

and it will send an e-mail message with a subject and body of “test” to the user you specify.

Postfix's logfile might vary a bit, depending on your system, but you should be able to find it in /var/log/mail.log or /var/log/maillog. That's the first place you should look if you find that some mail is not being delivered. The second place to look is the mailq command. That command will give you a quick status of all e-mail that is currently in the local spool along with its status. If all of your mail has been delivered successfully to other hosts, the output will look something like this:

$ mailq
Mail queue is empty

It's truly that simple. Of course, mail server administration definitely can become more complex than this when you want to do more than relay your own personal e-mail. But, it's good to know that simple configurations like the above are possible. If you are like me, saving time on the Postfix configuration just gives you extra time to tweak your mutt config.

Kyle Rankin is a Systems Architect in the San Francisco Bay Area and the author of a number of books, including The Official Ubuntu Server Book, Knoppix Hacks and Ubuntu Hacks. He is currently the president of the North Bay Linux Users' Group.


Kyle Rankin is Chief Security Officer at Purism, a company focused on computers that respect your privacy, security, and freedom. He is the author of many books including Linux Hardening in Hostile Networks, DevOps Troubleshooting and The Official Ubuntu


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

inspired me

katto's picture

I enjoyed this so much it inspired me to finally set up my mail.
3 days later I have a working system!
Mostly, this was me being dense, but I do have a couple of points to add to the above: in /etc/postfix/main.cf:

1) the relayhost DNS must be surrounded with [] if it is an alias
2) the smtp_generic_maps property must be used to specify the file containing the mapping of the local email address to that of the relayhost account.