How-To: Build A Cheap, Reliable Mail Server Using FreeBSD
We'll show you how to build a cheap, reliable mail server, using simple PC hardware and freely-avalable open-source software, including one of the world's most reliable server operating systems. (Part One of a series.)
Three Steps to Configuring Postfix
Now that you've installed FreeBSD, it's time to work with Postfix. Although we have a basic Postfix installation already, you'll need to customize it for your specific server.
The Postfix configuration is stored in the file /usr/local/etc/postfix.main.cf. You should read through this file to become familiar with the many options you can configure. You'll need to make some edits to main.cf to customize it for your system. Note: Lines beginning with a hash mark ("#") are commented out; delete the hash mark to have Postfix read that line.
Here are three steps for customizing the Postfix installation:
Set the hostname that will be used in the SMTP banner. Open main.cf in your editor, and find the line that begins myhostname. Mine reads: myhostname = postoffice.davemarkowitz.net Find the line starting mydomain, and change it to your domain. For example, here's mine: mydomain = davemarkowitz.net After you finish editing main.cf, restart Postfix to have it run with the new configuration, like so: % postfix reload
Five Steps to Installing and Configuring Dovecot
Now you'll install and configure Dovecot to provide POP and IMAP services. Here's how:
Install the Dovecot package from the installation source you selected when installing FreeBSD. Do it with this code: % pkg-add "r dovecot Answer Yes to all questions the installer asks. Once the installer finishes, create the dovecot configuration file /usr/local/etc/dovecot.conf. Do so by making a copy of the sample provided to you, like so: % cd /usr/local/etc % cp dovecot.conf.sample dovecot.conf Because of the way FreeBSD handles permissions for /var/mail, where incoming mail is stored, you must edit dovecot.conf to give the "mail" group write access to /var/mail. Find the line that reads: #mail_extra_groups = and change it to: mail_extra_groups = mail I suggest reading through dovecot.conf to familiarize yourself with its various configuration options. For example, you can specify the IP address dovecot will listen on for IMAP or POP logins. Or you can enable SSL/TLS support by finding the line that reads ssl_disable = yes and changing it to ssl_disable = no. Dovecot should start whenever the system boots, so in /etc/rc.conf, add the following line: dovecot_enable="YES"
Three Steps to Creating Users Before your end users can send and receive e-mail, they'll need accounts on the server. Since this is a single-domain server and we're not using virtual domains, we will create system accounts in FreeBSD. Postfix and Dovecot will use these system accounts. Here's how to do it:
When the server is built following the instructions in this Recipe, it will provide e-mail service to users with FreeBSD system accounts (for example, "dave"—who we created earlier). To add more users, use the adduser command:
% adduser fred
After that, just follow the prompts. When your users want to login to the server and retrieve their e-mail using a POP or IMAP client, they'll use the username and password you've created.
After you're finished, reboot the system to make sure everything is working correctly, by using this command:
% shutdown "r now
Error messages for troubleshooting will be logged in files within /var/mail.
That's it! If you've followed the steps in this Recipe, you now have a basic e-mail server for a single domain.
This is Part 1 of a two-part TechBuilder Recipe. Part 2 looks at extending the basic e-mail server with Webmail access, antivirus scanning, and spam filtering. DAVID MARKOWITZ is a computer network and integration consultant who serves small and medium businesses and home users in and around Philadelphia.
About the Author
You May Also Like