A number of years ago, when GMAIL was just starting to get popular; there was privacy controversy over the fact that Google was scanning the contents of your emails in order to show contextual ads. Just as the tech press was starting to go ballistic over this story, I was making the decision about where to host email for personal domains.
There were two options
- Build my own email server
- Use a hosted service.
- At this time, given my list of requirements, GMAIL was the only option.
Using GMAIL was and still is the obvious answer. Google runs a mail service so much better than I can. And all the time I would spend installing patches and figuring out why SPAM is getting through, for example, could be spent doing better things like skiing or spending quality time in a hammock in my backyard.
In my head I understood that GMAIL was the way to go, but I could not shake the feeling that running my own server was the best and only option. Looking back I realize the reasons for this were:
- I wanted to own my email messages. I wanted to make sure I could access messages from yesterday, from 1 year ago and from 15 years ago. They are mine and I do not want a company or government take-down order to block my access to them.
- (This one is a bit irrational(as email is like a postcard, anyone can read it at any point in the journey)) By hosting my own email server, I could make sure there was one less large corporation reading my email.
With the decision to run a blog at http://www.fourproc.com, I needed to add a few more domains to this email server. In order to do this I had to enable Virtual Hosting support in sendmail. This is surprisingly easy to do.
Add Virtual Hosting support in sendmail
Enable virtusertable feature
Virtusertable is essentially an alias file. It allows you to route incoming email addresses from multiple domains to the appropriate mailbox. (See the virtusertable section at http://www.sendmail.org/m4/features.html for more information)
Edit the sendmail configuration file
vi /etc/mail/sendmail.mc [added] FEATURE(`virtusertable')dnl
Create and configure the virtusertable file. (Below is a sample file)
vi /etc/mail/virtusertable [added] # Email addresses for fourproc, 4proc email@example.com brian firstname.lastname@example.org user2-fourproc email@example.com user2-fourproc firstname.lastname@example.org user4-fourproc email@example.com brian @4proc.com %firstname.lastname@example.org # Catch-all addresses for each domain @fourproc.com catchme
Create the virtusertable db file
makemap -r hash virtusertable.db < virtusertable
This table will route incoming messages in the following way
- Incoming messages to email@example.com will be delivered to brian’s mailbox
- Incoming messages to firstname.lastname@example.org will be delivered to user2-fourproc mailbox
- Incoming messages to email@example.com will be delivered to user2-fourproc mailbox
- Incoming messages to firstname.lastname@example.org will be delivered to user4-fourproc mailbox
- Incoming messages to email@example.com will be delivered to brian’s mailbox
- Incoming messages to any other email address in fourproc.com domain will be delivered to the catchme mailbox
- Incoming messages to any email address in 4proc.com domain will be delivered corresponding user in the fourproc.com domain.
Enable generic_entire_domain feature
The genericstable and generics-domain features control the routing of outgoing email address. If the genericstables and the
GENERICS_DOMAIN_FILE features are enabled, then sendmail will masquerade the from address and the envelope if the FROM addresses domain is in the
GENERICS_DOMAIN_FILE file. (See the genericstable section at http://www.sendmail.org/m4/features.html
Edit the sendmail configuration file
vi /etc/mail/sendmail.mc [added] FEATURE(`genericstable')dnl GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
Create and configure the genericstable. (Below is a sample file)
For my case, no entries in the table were needed. Create the generics table db file
makemap -r hash genericstable.db < genericstable
Create and configure the generics-domains file. (Below is a sample file)
vi /etc/mail/generics-domains [added] domain1.com fourproc.com 4proc.com domain2.com domain3.com
Start sendmail using the new configuration
The first thing I need to do is create the new sendmail.cf configuration file
cd /etc/mail make -C /etc/mail
Now I can restart the sendmail server
That was it. It was pretty simple. Took me a few hours total to research how to do it, test the configurations on a spare AWS instance and rollout to the production server. This was probably 8X longer than it would have taken me to rollout these domains using Google Apps. Maybe sometime in the future, my reasons for running my own email server will no longer matter to me and I will move over to GMAIL or another service. But for now, I am sticking with running my own.