How to Setup Email Archiving Server with Postfix on Ubuntu 22.04
Introduction
Email archiving means keeping a copy of all incoming and outgoing emails in a safe place.
In production environments, companies must store emails for security, legal compliance, and backup.
With Postfix on Ubuntu 22.04, we can set up an email archiving server so no email is ever lost.
Concept of Email Archiving
Postfix allows us to make a copy of every email using the always_bcc
or recipient_bcc_maps
parameter.
This ensures that whenever a user sends or receives an email, a copy is delivered to a special archive mailbox.
Step 1: Prerequisites
- Ubuntu 22.04 server with Postfix installed
- A working mail domain (example: bitscentric.local)
- Admin user with sudo access
Step 2: Update System
sudo apt update -y && sudo apt upgrade -y
Step 3: Install Postfix (if not installed)
sudo apt install postfix mailutils -y
Choose “Internet Site” when asked during installation.
Set system mail name as bitscentric.local
.
Step 4: Create Archive Mailbox
We will create a mailbox called archive@bitscentric.local to store all email copies.
sudo adduser archive
Set a strong password for this account. This user will collect all archived emails.
Step 5: Configure Postfix for Archiving
Edit Postfix main configuration file:
sudo nano /etc/postfix/main.cf
Add the following line at the bottom:
always_bcc = archive@bitscentric.local
This will send a copy of every incoming and outgoing email to archive@bitscentric.local
.
Step 6: Restart Postfix
sudo systemctl restart postfix
Step 7: Test Archiving
Send an email from any user in your domain:
echo "Test Archive" | mail -s "Archive Test" user@bitscentric.local
Now check the archive mailbox:
mail -u archive
You should see a copy of the test mail.
Step 8: Storing Archive Mails Safely
For production use, you should store archived mails safely:
- Use Dovecot IMAP to allow secure access to
archive@bitscentric.local
. - Set up a backup system (rsync, Borg, Restic) to copy
/var/mail/archive
regularly. - Use a dedicated storage server for archiving if mail volume is high.
Advanced Option: Archive Specific Domains or Users
Instead of archiving all emails, you can configure per-user or per-domain archiving.
Create a BCC map file:
sudo nano /etc/postfix/recipient_bcc
Add rules:
@bitscentric.local archive@bitscentric.local
ceo@bitscentric.local legalarchive@bitscentric.local
Convert into database format:
sudo postmap /etc/postfix/recipient_bcc
Edit /etc/postfix/main.cf
and add:
recipient_bcc_maps = hash:/etc/postfix/recipient_bcc
Restart Postfix:
sudo systemctl restart postfix
Step 9: Security Best Practices
- Restrict access to archive mailbox (only administrators should access).
- Use encryption (TLS/SSL) for archiving server.
- Implement retention policies (e.g., keep emails for 5 years).
- Regularly backup the archive mailbox.
- Monitor mail logs (
/var/log/mail.log
) to confirm archiving works.
Conclusion
Email archiving is critical for production mail systems.
By using Postfix on Ubuntu 22.04, we can easily set up an archiving server where all user mails are copied for security and compliance.
With best practices like secure access, backups, and retention policies, your company can protect important communication and meet industry standards.