mail hosted at Google, web server elsewhere

This post aims to cover two sets of questions that frequently appear on Serverfault:

“I have the email of my organization hosted at Google and the web server at a hosting provider. When the web server sends email (when a form is completed for example), email is received by everyone except when the recipient is in our domain. Then sendmail tries to deliver locally and not over at Google”. Or, “certain recipients, including Google, reject email from the web server (or servers withing our LAN) as spam”.

There are answers at Serverfault recommending the use of ssmtp in order to forward all sending email via Google, but this requires SMTP authentication and a password saved in a file.

For the purposes of this post the domain will be used.

Configure SPF for

SPF is framework that allows the domain name owners notify the world who they believe the appropriate servers sending mail on behalf of their domain are. Google support pages note that the SPF record should at least be in the form of v=spf1 ~all. However, it is also needed that be able to send email on behalf of So the appropriate record becomes:

v=spf1 ~all

Note: is not the same domain as

Configure sendmail for is included in /etc/mail/local-host-names, which means that treats this a local domain and will try to deliver locally, instead of Google. The following additions to the sendmail configuration file ( take care of this:

Kbestmx bestmx -T.TMP

R $* < @ > $*
    $#esmtp $@ [$(bestmx $)] $: $1 < @ > $2

The line is broken in two for readability. As always remember that the LHS and the RHS of the rule are separated with tabs and not spaces. So do not copy-paste. Build and install, restart sendmail and check.

I would welcome additions on how the same can be achieved with postfix or exim.

4 thoughts on “mail hosted at Google, web server elsewhere

    1. Since I am not into Logistics or the Freight Forwarding business, I find the above pingback highly amusing.

        1. I too consider it as spam. I let it live to make a point about automatically rss fed sites. The site in question seems to be feeding on posts written by users of the OR-Exchange. Given that I like reading about OR but I am not writing about OR, I will contribute a fair amount of noise to it :)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s