it is a bit fuzzy thing I try to solve so I need to ask you for a help.

Our users are divided between two big buildings, that are far from each other, so we set up two independent mail servers so each server serves mail for its building. Main purpose is that in case of connectivity lost users are able to mail their colleagues within its own building even if external mail is temporarily not available. Each building uses its own mail domain. The setup is trivial and works fine.

For purpose of spam combat and also for administrative purposes we have the same (whole) user table on each server, but have each box marked as "B1" or "B2" to indicate which building given user located at. We used to store tables of mailboxes and redirects in SQL tables so no problem to distinguish them by adding "WHERE which_server='B1'" condition to exim configuration lines.

What was unexpected is mail duplication when we come to redirects/aliases. Here is the example:

Let's say user user1 in building 1 uses mailbox user1@b1.domain.com, while user user2 in building 2 uses mailbox user2@b2.domain.com. No problem so far, they can send mail to each other and external users can also contact them by mail.

Let's now imagine we add some redirects on each mail server. Say like that:

user2@b2.domain.com -> user2@b2.domain.com, user3@b2.domain.com, foobar@gmail.com

Now as mail from user1@b1.domain.com goes to user2@b2.domain.com, mailserver on server1 will make three copy of it and send further as three separate messages (two gwill go to b2.domain.com's server, one will go to Gmail's servers). Now, when these messages are come to b2.domain.com's server, it will do the redirect again (using its own SQL tables), thus duplicating messages.

I fee I miss some elegant way to solve this so could you please point me out the right way?

Thanks in advance!

  • If the user wants to keep a copy of the email then it seems like redirect is the wrong thing to do, but I can't think of what the right thing is right this second.
    – DerfK
    May 14, 2014 at 14:25
  • @DerfK users are simple want to see their mail boxes, nothing more. Imagine they all use IMAP so copy of each user's mail should be stored on their server.
    – Alexander
    May 14, 2014 at 14:40

2 Answers 2


You do have one powerful indicator that you're not using when analyzing your aliases table expansion: whether the email comes from the outside world, or if it comes from the other building (one or more hostnames or IPs). If the problem is that the alias expansion in B1 fails in a duplicate sort of way when it's sent from B2, then skip the alias expansion if the source is B2. In an ACL, this would be done with a hosts = !+B2, however in your case, the routers are where you need this decision to be made. In order to do this, I would set in the connect ACL or mail ACL:

warn hosts = +B2
     set acl_c_other_building = 1

Then in the aliases router, you can add the condition that if it's from the other building, return false/no:

condition = ${if eq{$acl_c_other_building}{1} {no}{yes}}

With this logic in place, presumably the following routers are those which handle mailbox delivery and will deliver that message locally.

If it works as expected, do the reverse in the other building.

  • I've given it a try, and looks like it helped. Thank you, I almost forgot to add labels like this while work with source IP.
    – Alexander
    May 19, 2014 at 12:57

Your main problem seems to be an inconsistent mail environment. On one hand you treat the two servers like identical inhouse servers (same alias rules), on the other hand they are only responsible for one domain only which makes them treat each other like any other remote mail server, so redirect duplications are bound to happen.

Instead of trying to handle this distributed setup on the MTA routing level I'd suggest you give both servers the same domain configuration, which means make both servers treat both your domains as local and deliver to local mailboxes and then have these mailboxes replicated between the servers, for example using dovecot's master-master replication

  • Nice idea, and I evaluate it in the first place but there are a lot of in-house mails so I won't spend storage and bandwidth to store and send mostly useless messages.
    – Alexander
    May 14, 2014 at 14:37

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.