I ran into a misconfiguration that was preventing me from using sendmail to send messages to my Google Apps account. While searching for an answer I found other people with this problem, but it still took some detective work to figure out. Sendmail ignores the MX record and tries to find the user locally. When it doesn't find the recipient, it kicks the mail back to /var/mail/user-name. Otherwise sendmail is happy sending emails anywhere else that you like. This happens when sendmail looks at your hostname and decides that the recipient must be a local user. In order to skirt around this we need to set the hostname to something different and use masquerading in the sendmail configuration.
Verify your MX Records are Correct
The first thing you'll want to do is verify that your MX Records are correct using nslookup. You should see something similar, though not exact, to the following. If your MX Records do not look like this, reference Google's documentation help configuring your MX records. If the MX Records aren't right, no amount of troubleshooting is going to help.
> set type=mx
mydomain.com mail exchanger = 10 ASPMX.L.GOOGLE.com.
mydomain.com mail exchanger = 20 ALT1.ASPMX.L.GOOGLE.com.
mydomain.com mail exchanger = 30 ALT2.ASPMX.L.GOOGLE.com.
mydomain.com mail exchanger = 40 ASPMX2.GOOGLEMAIL.com.
mydomain.com mail exchanger = 50 ASPMX3.GOOGLEMAIL.com.
Set a New Hostname
Once we're sure that our MX Records really do point to the right servers, we can check our hostname. We should ensure that both our /etc/hostname and /etc/hosts files contain a fully qualified domain name. Then we need to make sure that name is different than the one we're using for Google Apps. If /etc/hostname does not exist, you must create it.
A simple naming scheme is to name your host www .mydomain.com, then later have sendmail masquerade as just mydomain.com. With that configuration mail sent from mydomain will no longer be seen as local, but will still originate from mydomain. You may use any valid hostname you like, just as long as it's not the same as your Google Apps.
$ hostname www.mydomain.com
$ vim /etc/hosts
127.0.0.1 localhost www.mydomain.com
Now all we need to do is tell sendmail to use the right domain when sending. Take vim and head over to /etc/mail where you'll find all of sendmail's configuration. We're going to add three lines to the sendmail.mc
Note that those aren't plain quotes, they're back ticks ` followed by single quotes '. The DONT_PROBE_INTERFACES definition fixed the problem for some people. It did not work for me but may end up working for you.
We'll need to rebuild the sendmail configuration, then restart the sendmail daemon for the changes to go live.
$ /etc/init.d/sendmail restart
That Should Be It
You should be able to send email to your Google Apps accounts after this. Any host named after its self was vulnerable to this misconfiguration. You could get away with skipping the Masquerading and using the -f flag when using sendmail.