First and foremost I should advise that this article explains how to setup Virtual Domains that are not connected to Linux users. The premiere source of information on the subject, and as some in the IRC channel have called it, “the word of god”, is postfix.org.
The first step is to actually install postfix:
sudo apt-get install postfix
Once installed you must do the basic configuration of postfix required to receive and send emails from your domain.
I suggest you look at “basic postfix configuration” to learn how to setup your domain name and relay hosts.
For me it was important to setup the mail relay for my application server, and to have the postfix HELO set as my Mail Exchange DNS / rDNS.
Reverse DNS is important, since hosts like AOL will reject mail from your IP address if your HELO doesn’t match the reverse look up.
That done, I wanted to be able to create users under a variety of domains. The section titled “Postfix virtual MAILBOX example: separate domains, non-UNIX accounts” was the key to this quest. I chose this because I wanted to minimize the attack surface on the box, by limiting the amount of valid users. There is a way to create users without shell access, but I preferred not to create users at all, it was just a better reflection of what the box is for.
The main point of this article, is to highlight the pieces I was missing, having done these two things!
So here is what I needed:
#1 I needed to go ahead and turn the /etc/postfix/vmailbox file and /etc/postfix/virtual file into .db files which postfix needs.
sudo postmap /etc/postfix/vmailbox
sudo postmap /etc/postfix/virtual
This is due to the fact that tailing the /var/log/mail.log file showed this as an issue.
#2 I realized I completely overlooked setting the correct UID and GID for the postfix user!
sudo cat /etc/passwd | grep postfix
Revealed the correct id’s for the virtual_uid_maps, virtual_gid_maps attributes for the /etc/postfix/main.cf file.
#3 I reloaded postfix, but emails were still not being delivered. The virtual domains map to the base path on the file system set in the virtual_mailbox_base. And those directories did not exist yet.
sudo mkdir /var/mail/vhosts
sudo mkdir /var/mail/vhosts/winwinhost.com
sudo chown -r postfix:postfix /var/mail/vhosts
And that was it, those were the missing pieces. Remember to tail the mail log. This will really help you identify what is going wrong with the configuration. If you join the #postfix channel on freenode IRC, please remember to be courteous, use pastebin to expose your logs, and use complete sentences with proper English punctuation and grammar.
Thanks for reading, and I hope this helps someone out there, in the interwebs.