Forwarding all email to a domain with sendmail
I just bought a new domain name (bitsofpancake.com) — I’m actually quite proud of that name, to be honest! I decided that I would forward all the email addressed to it (firstname.lastname@example.org) to my personal email. I had previously done that with a convoluted combination of Google Apps and its catch-all email feature, but this should be much less roundabout. Or so I thought: figuring out how to set it up was a pain.
First, I needed to allow sendmail to function as an external mail server.
I’m on Ubuntu Natty, and the sendmail config files are located in /etc/mail/. It turns out that the sendmail.conf is so complicated that there’s a separate file, sendmail.mc, that is designed to be edited and then “compiled” into the real config file.
I had to change this line in sendmail.mc:
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl
DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp')dnl
This change tells sendmail that it’s okay to allow external users to send email (source).
Next, I had to enable the virtual user table. I added this line to the same file (sendmail.mc) (source):
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
I made a file in /etc/mail/ called virtusertable with this one line:
This catches all emails to @bitsofpancake.com and forwards it to my Gmail account. You can add more lines to this file to specify different forwarding rules (source).
I compiled the virtusertable using:
/etc/mail$ sudo makemap hash virtusertable < virtusertable
Next, I added bitsofpancake.com to /etc/mail/local-host-names — this file tells sendmail which domains to consider "local." (Otherwise, it would keep on trying to send to itself in an infinite loop!)
Then, I reloaded and "compiled" sendmail's config with:
/etc/mail$ sudo sendmailconfig
Finally, I added port 25 (the port for SMTP) to my iptables firewall and updated my MX DNS records to point to the server — it works!