CentOS 7.x postfix based email archive server
<yambe:breadcrumb>CentOS_7.x_postfix_configuration|CentOS 7.x postfix configuration</yambe:breadcrumb>
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:
- Edit /etc/postfix/main.cf and add always_bcc=<receipient_address>. For example
- always_bcc=archives@backup.example.com
- 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.
Refer:
Archive with same username on destination as source
To archive with same username on destination as source use following steps:
- Edit /etc/postfix/main.cf
- sender_bcc_maps=pcre:/etc/postfix/sender_bcc_map
- recipient_bcc_maps=pcre:/etc/postfix/recipient_bcc_map
- In /etc/postfix/sender_bcc_map use:
- /^(.*)@<domainname>$/ $1@<backup-hostname>.<domainname>.com
-
- For example:
- /^(.*)@sbarjatiya\.com$/ $1@backup.example.com
- For example:
- Similalry in /etc/postfix/recipient_bcc_map use:
- /^(.*)@<domainname>$/ $1@<backup-hostname>.<domainname>.com
-
- For example:
- /^(.*)@sbarjatiya\.com$/ $1@backup.example.com
- For example:
- 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*.
- postmap /etc/postfix/transport
- systemctl reload postfix
Refer:
- https://www.vaultastic.com/docs/How_to_setup_email_archiving_for_postfix
- https://linux.die.net/man/5/transport
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:
- First setup a postfix and dovecot server using appropriate articles from Email server configuration
- Then edit /etc/postfix/main.cf with virtual_alias_maps using:
- virtual_alias_maps = pcre:/etc/postfix/virtual
- Create file /etc/postfix/virtual with following line at the bottom as catch-all
- /.*/ archives
- 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.
- 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.
Refer:
<yambe:breadcrumb>CentOS_7.x_postfix_configuration|CentOS 7.x postfix configuration</yambe:breadcrumb>