2

There are two mail domains on two Postfix servers, let's say a.com on server1.com and b.com on server2.com. Users and aliases are stored in an Active Directory, which we access by using the ldap module.

  • A copy of all mail to user@a.com on server1 should be forwarded to user@b.com.
  • A copy of all mail to user@b.com on server2 should be forwarded to user@a.com.

How would I prevent a mail loop in this scenario? Can I forward all mail except if it's coming from one domain?

mgabriel
  • 1,091
  • 9
  • 15

1 Answers1

0

If I understand the task well, always_bcc is not your friend.

I would try the transport daemon (transport table) instead.

in transport:

 a.com  smtp:[mail.relay.of.b.com]
 b.com  smtp:[mail.relay.of.a.com]

Of course, we suppose we want to forward to the same user name.


For the updated question: If you want to send copies, you can use the virtual alias transport. virtual_alias_maps = regexp:regexpalias

and in regexpalias do something like this:

 /.+@(a|b).com$/   $1@a.com,$1@b.com

after the usual postmap regexpalias matching mails should go for both destinations. You must be cautious if you have other virtual alias sources defined at the server, because virtual aliasing will be done only once, and exits at the first match. For example if you have:

 virtual_alias_maps = 
          hash:/etc/postfix/myaliases
          regexp:/etc/postfix/regexpalias

And in myaliases you forward bob@a.com to boby@a.com, then your regexp will be never reached and single mail will go to boby@a.com.

Because you are forwarding the mails directly (transport), and those servers supposedly wont sent the mail back, no more virtual aliasing happens, so there should be no mail loops.

goteguru
  • 302
  • 2
  • 12
  • I edited my question as I was not specific enough. I don't want to forward the original mail. I want to forward a copy of each mail. Sorry for being not clear. – mgabriel Jan 19 '17 at 16:06
  • oh, I see. And do you want to forward copy of bob@ b.com to allmails@a.com and alice@a.com to allmails@b.com (always_bcc does that) or a copy of bob@b.com to bob@a.com (and vice versa)? – goteguru Jan 19 '17 at 18:43
  • bob@b.com -> bob@a.com and bob@a.com -> bob@b.com - the same for alice, joe, etc. - but I need also to prevent a mail loop (bob@b.com -> bob@a.com -> bob@b.com -> ...) – mgabriel Jan 20 '17 at 07:40
  • answer modified. I hope that's what you need... – goteguru Jan 20 '17 at 16:41