Multiple Domains with Postfix Mail Server
I am now hosting multiple domains on DigitalOcean and require a solution for email. Before, I was happy with not setting up a mail server on my droplet and just using Gmail but a new project requires domain specific email addresses. Since my domain registrar points my DNS settings to DigitalOcean, I can’t use their mail services. I need to set this up myself and honestly, going through this postfix tutorial was pretty easy. Below, I will cover how to setup postfix for multiple domains and how to read postfix emails.
Once you have installed postix and verified that it works for one domain, it is not hard to enable additional domains. To make things simple, I am not creating multiple email users, I just want to capture incoming email to firstname.lastname@example.org, email@example.com, and firstname.lastname@example.org and have it all aggregated for the root user. Here’s how I did it:
1. Go to the Postfix directory: cd /etc/postfix
2. Open the virtual file: vim virtual
3. Add the email/domain mapping:
4. Open the postfix configuration file: vim main.cf
5. It should already be setup for domain1.com, so all we have to do is add other 2 domain under virtual_alias_domains:
Here’s how the some of the other params look like
myhostname = domain1.com
alias_maps = hash:/etc/aliases
virtual_alias_maps = hash:/etc/postfix/virtual
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = domain1.com, localhost, localhost.localdomain, localhost
6. Postmap and Reload:
You should be all set. Send a few emails and check to see if they made it to your server. If you are using the user root, you would see them show up by printing this file: cat /var/spool/mail/root. Now, how do you actually manage the mail as working with a text file does not seem very manageable.
How do you read postfix mail?
A simple solution is to install mailutils: apt-get install mailutils. After that you can just use the mail command or read up on more commands in the mailutils documentation. Also, you can just enter “help” or “list” after running the mail command for more information.
Since I needed more functionality, like finding emails by the receiving email address, I installed maildir-utils: apt-get install maildir-utils. Before using mu, we need to set Postfix to support Maildir:
1. Make Postfix use Maildirs instead of Mboxes:
sudo postconf -e "home_mailbox = Maildir/"
This just appends the setting to main.cf postfix configuration file.
2. Restart postfix: sudo /etc/init.d/postfix restart.
3. Send an email and test everything. Check the postfix log if there any errors: cat /var/log/mail.log. If you are doing this all for the root user you should be able to see the Maildir in the root home directory:
4. Index the mail via: mu index (It should work now that Postfix is using Maildir but before you would get an error like this:
mu: mu_store_new_read_only: xapian error ‘Couldn’t stat ‘/root/.mu/xapian’
Now you can search your mail using various mu commands. If you need more email management, like a good way to send emails or deal with attachments, check out some of these:
Finally, here is a comparison of various email clients.