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 (whatever@bitsofpancake.com) 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

into:

DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp')dnl

This change tells sendmail to accept external 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:

@bitsofpancake.com	forwardtothisemail@gmail.com

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!

March 25, 2012, 8:27pm by Casey
Categories: Server Administration | Tags: | Permalink | 2 comments

Comments (2)

  1. i followed these steps to allow my unix users to send email to external mail server using their local email addresse.
    it helps a lot,
    Thank You.

  2. For some reason, when I tried doing this again, sendmail refused to relay emails. After a lot of searching, I noticed that it was strangely changing casey@bitsofpancake.com to casey@localhost.com. I added “FEATURE(`nocanonify’)” to sendmail.mc, which solved the problem.

Leave a Reply

Required fields are marked *