CentOS 7.x postfix based email archive server

From Notes_Wiki
Revision as of 15:49, 28 August 2022 by Saurabh (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Home > CentOS > CentOS 7.x > Email configuration > Postfix configuration > CentOS 7.x postfix based email archive server

Archive to single recipient address

To archive (copy) all incoming and all outgoing emails from postfix to another server (Typically for compliance and backup) use:

  1. Edit /etc/postfix/main.cf and add always_bcc=<receipient_address>. For example
  2. systemctl reload postfix

The receipient address should not be on the same email server / domain. You can use a sub-domain such as archives@backup.example.com where backup.example.com email server is different than example.com email server.


Archive with same username on destination as source

To archive with same username on destination as source use following steps:

  1. Edit /etc/postfix/main.cf
  2. In /etc/postfix/sender_bcc_map use:
    /^(.*)@<domainname>$/ $1@<backup-hostname>.<domainname>.com
    For example:
    /^(.*)@sbarjatiya\.com$/ $1@backup.example.com
  3. Similalry in /etc/postfix/recipient_bcc_map use:
    /^(.*)@<domainname>$/ $1@<backup-hostname>.<domainname>.com
    For example:
    /^(.*)@sbarjatiya\.com$/ $1@backup.example.com
  4. Optionally, if MX record lookup is not desired and mails need to be delivered to some other address, edit /etc/postfix/transport
    backup.example.com smtp:[in.example.com]:2025
    Here, SMTP server on in.example.com is running on port 2025. Also backup.example.com need not be a valid FQDN or it can be different from in.example.com. *If IP address is used then [] are required around the IP address*.
  5. postmap /etc/postfix/transport
  6. systemctl reload postfix


Archive all emails irrespective of sender or recipient

It is possible to create a postfix archive server which accepts all emails from any sender to any recipient. This is desirable to build some kind of archive server for backup or compliance.

To build such server use following steps:

  1. First setup a postfix and dovecot server using appropriate articles from Email server configuration
  2. Then edit /etc/postfix/main.cf with virtual_alias_maps using:
    virtual_alias_maps = pcre:/etc/postfix/virtual
  3. Create file /etc/postfix/virtual with following line at the bottom as catch-all
    /.*/ archives
  4. Make sure user archives exists on the server
    getent passwd archives
    If user is not present create using 'useradd archives' or other appropriate user creation mechanism.
  5. systemctl reload postfix

Note that steps do not have way of cleaning up old emails after certain date. That could be done easily using grep (Date in email header) or find (file creation timestamp) or custom file processing. If mails are stored in maildir format, ie one email per file, then cleaning could be easier as it just requires file deletion. (Ref http://wiki.dovecot.org/MailLocation ).

Since all emails are coming to one single folder we can also consider using scripts (or logrotate) to create one separate folder for each days emails. Searching across many folders using command-line or using squirrelmail etc. interface would be possible.


Home > CentOS > CentOS 7.x > Email configuration > Postfix configuration > CentOS 7.x postfix based email archive server