Redirecting User Email To Google With Postfix

Note: Now that Google is hosting email domains for free, it has become an interesting alternative for both new and old domains. As always, I've changed the names to protect those affected.

Transitioning a domain to Google can be an arduous task. Once you have set up the domain with Google and added all the users, it may seem that the only option is to flip the switch and route all email to Google via your <acronym title="Mail eXchange">MX</acronym> records. If you are using Postfix, you can redirect individual users. This gives you the opportunity to prepare each individual user to use Google before flipping the final switch.

Postfix LogoThe key aspects of Postfix that allow this to work are relay domains, virtual alias domains, and the trivial-rewrite daemon (via the transport table). The concept that is hard to grasp is that you are not going to redirect individual users to Google, but the entire domain. Then, you'll force local users to stay local until you have migrated them to Google. Here's an example using the domain and three users: Jim, Fred, and Betty.

  relay_domains      = hash:/etc/postfix/relay_domains
  transport_maps     = hash:/etc/postfix/transport
  virtual_alias_maps = hash:/etc/postfix/virtual

/etc/postfix/relay_domains  OK

/etc/postfix/transport  smtp:ASPMX.L.GOOGLE.COM

/etc/postfix/virtual betty  fred   jim

Note that we did not include the usual "domain_name any_text" syntax before the virtual aliases in /etc/postfix/virtual. Although this would be common in a normal virtual alias domain set up, we want to only virtual alias for particular user names, not the whole domain.

In this configuration, email for all three users is being delivered locally (in this case, to real UNIX users). When a user is ready to be forwarded to their Google account, simply comment out the entry in /etc/postfix/virtual and rebuild the hash table with postmap.

Note: Wietse Venema, the creator of Postfix, explained how to do this in the Postfix mailing list in January 2000. That's the only documentation I could find that gave a good example of what to do.

My Bookshelf

Reading Now

Other Stuff