We help IT Professionals succeed at work.

Auto duplicating incoming & outgoing email

Medium Priority
Last Modified: 2012-05-06
I have linux server using Exim.

I'd like to know how can I configure exim to make a duplicate copy of incoming & outgoing of the email accounts in the server.

Watch Question

Top Expert 2009

i never done this
but are you after something like this




Can you copy the contents over? coz I can't access the page.
Top Expert 2009

Saving copies of all email using Exim
24 Mar 2006

I've often seen questions on lists by people who want to save all incoming and outgoing mail on a specific server in an archive, this is usually due to some auditor requesting it or corporate legal types requesting it.

The Exim documentation says it can be done but does not give examples neither does any of the two Exim books, the mailing lists are short of working examples and Google does not help either! Eventually came across a russian language site that had a working setup so I figured I'd document it here in English.

The basic idea is I want a maildir made that has sub folders for each user containing incoming and outgoing mail.

You'll need to use 2 types of Exim configuration, one being a System Filter and one being a Shadow Transport.

Handling outgoing mail is done using the system filter, I'll set this up to only affect mail matching domain.com. In the main Exim configuration configure the basics of system wide filters by simply adding the following to the top section:

    system_filter = /etc/exim/systemfilter.txt
    system_filter_directory_transport = local_copy_outgoing

This defines the file where the filter will live as well as a transport that will be used to delivery the mails created by the filter. You could potentially use one of your existing transports, I like using a separate one for clarity, in your transports section add the local_copy_outgoing:

      driver = appendfile
      group = exim
      user = exim
      mode = 0660
      maildir_format = true
      create_directory = true

NOTE: This is using user exim and group exim, you want to adjust it for your local needs.

Now simply create the filter in /etc/exim/systemfilter.txt:

    if $sender_address_domain is domain.com
    unseen save /var/mail/domain.com/mailarchive/.${tr{$sender_address}{.}{_}}.outgoing/

This filter will save the mail in a maildir under /var/mail/domain.com/mailarchive/ the mailbox for a name.surname@domain.com user will be name_surname@domain_com.outgoing using this format means most IMAP clients will display it nicely since .'s tend to confuse them a bit. You can adjust this to taste.

Incoming mail is easier, Exim provides a shadow_transport facility that lets you call another transport for each local delivery, this transport will get a copy of the mail and its result won't affect the further deliver of the actual email, perfect for calling vacation type commands or doing this kind of mail copying.

My needs are only for intercepting mail that reaches the Maildir's so I'll only need to hook into my address_directory transport, if you have other needs like intercepting actual real unix account emails then you can hook into the local_delivery transport using the same method. My address_directory transport looks like the one below, the last 2 lines are the important ones.

      driver = appendfile
      directory_mode = 770
      shadow_transport = local_copy_incoming
      shadow_condition = ${if eq {$domain}{domain.com}{yes}{no}}

This calls a transport called local_copy_incoming to deliver the copy of the email, just add the following into your transports again adjusting user id, group id and file paths to your liking. This will do the file name expansion in a similar format I'm just using a slightly more complex form of the text replace here as a different example of things you can do, end result is the same.

      driver = appendfile
      directory = /var/mail/domain.com/mailarchive/ \
          .${tr {$local_part}{.}{_}}@${tr {$domain}{.}{_}}.incoming/
      group = exim
      user = exim
      mode = 0660
      maildir_format = true
      create_directory = true

NOTE: The above line that ends in "\" is a continuation onto the next, remove the "\" and join the two lines in your config.

You can now restart your Exim server, if you've done it all right and created the main Maildir where this all live under your incoming and outgoing mail for domain.com will all be saved on a per user basis.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.