Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use my laptop at work on wireless and wired networks, at home on a wireless network, and at various other places (such as conferences, friends houses, etc).

When at work I'd like postfix to use the corportate mail server to route emails. When at home I'd like it to use my personal mail server to route emails. When elsewhere I'd like to have the laptop attempt to deliver email in the normal smtp fashion.

Is this possible using just postfix? Do I need something else (such as Lamson, or scripts that dynamically patch my postfix configuration) when I want to do routing that depends on my current location?

share|improve this question

You could (mis-) use the sender_dependent_relayhost_maps configuration option of Postfix by having two (or more) user accounts and using them according to the network environment you are in. This of course requires manual intervention for changing the user account in your MUA, but since most mail clients support multiple identities this shouldn't be a big problem.

Another possibility is to use the hooks your operating system might offer for networking. Most Linux distributions have the possibility to run custom scripts on network connection (and disconnection). You could write a small script which checks the ESSID of the access point you are connected with and set the relayhost configuration option (e. g. using postconf) for your Postfix installation.

share|improve this answer

I think you should use three different configs and let the network init scripts (se joschi's answer) "install" the appropriate one based on your location.
This way you can have correct values for $mydomain and everything else depending on your specific whereabouts. I think there's a pretty good chance that your outgoing mails will be too ugly (spammy) otherwise.

share|improve this answer

Use a script to detect which network you're on during (or shortly after) initialization which runs postconf -e relay_host=foo where "foo" is the correct mail server name for the network you're on.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.