I have a scenario where I have:

  1. Postfix server M (Stores mail)
  2. Postfix Server A (Relays mail using internet connection IA)
  3. Postfix Server B (Relays mail using internet connection IB)
  4. Internal DNS Server (does local name resolution)

Server M, A and B reside in a same network LAN, that means even when the internet connections IA and IB drop, the communication between M & A and M & B won't necessarily drop, so I can't use Postfix's smtp_fallback_relay option for this.

Now, I need server M to submit only to the server that will have internet connection at the time of relaying to it.

How can we do this best?

What we tried

My colleague and I shared two alternatives (Not exhaustive):

  1. Create the script to take the relay mails offline from the "LAN" in the perception of the mailstore (M), so that it falls back to its fall back relay
  2. Create a script on dns server (D) {or in etc hosts on M, whatever is better, but essential DNS for M}, that alters mail-relay.ourdomain.com to point to the server mail relay A or B that has internet access with a TTL small enough (say 5 seconds)

Both these options work for the most part, what I need is why they would not work (any danger of using one of them)?

  • 1
    One possible scenario is race condition, i.e. when M send email to A the internet was still working. But when A want to send email, the internet wasn't working anymore. – masegaloeh Aug 24 '15 at 15:40

The problem for either approaches is racing condition, i.e. your internet was working A or B acknowledge successful delivery to them but, when A or B trying to forward it to the internet, the connection was gone.

Above scenario was possible because how email flows in postfix.

Email from client ---> Received ---> Queued -> Sent

Postfix in server A will sent acknowledgement to M that email has been accepted by A when email has been queued. So, it's possible when postfix try to send email to the internet, the connection is cut and your email will queued until connection was back again.

Note: This behavior was expected in typical MTA. Remember that SMTP is store and forward protocol.

  • Thanks for this, yes this is a common problem probably just inherited from the usual 'mail server -> relay' setup as you point out that its inherently MTA – Gift Rise Aug 26 '15 at 6:36
  • One possible alternative is placing SMTP proxy instead of postfix in A or B. Another alternative is using smtp_fallback_relay in A or B (dislaimer, I haven't tested this :)) – masegaloeh Aug 26 '15 at 7:47
  • 2
    Your second alternative will work, except for this: To prevent mailer loops between MX hosts and fall-back hosts, Postfix version 2.2 and later will not use the fallback relays for destinations that it is MX host for (assuming DNS lookup is turned on). postfix.org/postconf.5.html#smtp_fallback_relay. This prevents one or two common uses of say relay_domains for filtering relay mail. ((I think also :)) – Gift Rise Aug 26 '15 at 8:10
  • @GiftRise From the question text it seems server M is MX, which relays through A and B. So this should be possible, isn't it? – sebix Aug 26 '15 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.