Postfix maildrop Directory Bloat: Understanding and Resolving Cron Email Accumulation in CentOS 7


2 views

When we uninstalled Postfix from our CentOS 7 server, we discovered a shocking surprise - over 9GB of space consumed by hundreds of thousands of files in /var/spool/postfix/maildrop. This directory should normally be empty or contain temporary mail files in transit. So what went wrong?

In a healthy system, cron jobs configured to email their output would follow this flow:

1. Cron executes job
2. Output gets captured
3. Postfix receives email with output
4. Email gets delivered to recipient's mailbox (like /var/spool/mail/root)

Several scenarios could create this maildrop buildup:

  • Postfix not running when cron jobs execute
  • Misconfigured mail system preventing delivery
  • Recipient mailbox issues (full disk, permission problems)

To diagnose your exact situation, these commands would help:

# Check if Postfix was running during cron execution
sudo journalctl -u postfix --since "1 month ago"

# Verify mail queue status (when Postfix was installed)
postqueue -p

# Check cron job configurations
sudo crontab -l

Even without Postfix, you can implement these safeguards:

# Option 1: Redirect cron output to /dev/null
* * * * * /path/to/script >/dev/null 2>&1

# Option 2: Log to files instead of email
* * * * * /path/to/script >> /var/log/cron.log 2>&1

# Option 3: Install a lightweight MTA like ssmtp
sudo yum install ssmtp

When dealing with hundreds of thousands of files, never use rm *. Instead:

# Safe deletion method for large quantities
find /var/spool/postfix/maildrop -type f -delete

# Alternative with progress monitoring
rsync -a --delete /empty_directory/ /var/spool/postfix/maildrop/

This incident highlights how services interact invisibly. When removing a package like Postfix:

  1. Audit dependent services (cron, logwatch, etc.)
  2. Check configuration alternatives
  3. Monitor disk space after removal

When working with CentOS 7 systems, many administrators encounter a puzzling situation where the /var/spool/postfix/maildrop directory becomes overloaded with thousands of files, often consuming significant disk space. This typically occurs when:

  • Cron jobs generate output but have nowhere to send it
  • Postfix is misconfigured or removed while cron emails remain in queue
  • Mail delivery fails silently without proper logging

Here's what happens under the hood when cron jobs and Postfix interact:

# Typical cron job that generates output
* * * * * /path/to/script.sh > /dev/null 2>&1  # Properly suppressed
* * * * * /path/to/script.sh                   # Will generate email if output exists

The key components involved:

  1. Cron attempts to email output to the job owner (root by default)
  2. Postfix receives the email and stores it temporarily in maildrop
  3. If Postfix cannot deliver (or is uninstalled), files accumulate

To safely remove the accumulated files:

# Basic cleanup (run as root)
find /var/spool/postfix/maildrop -type f -delete

# More cautious approach with logging
find /var/spool/postfix/maildrop -type f -print -delete > /var/log/maildrop_cleanup.log

Several technical solutions exist:

Option 1: Properly suppress cron output

# Redirect all output to /dev/null
* * * * * /path/to/script.sh > /dev/null 2>&1

Option 2: Configure cron to use a different mailer

# In /etc/crontab
MAILTO=""

Option 3: Reinstall and properly configure Postfix

yum install postfix
systemctl enable postfix
systemctl start postfix

For persistent issues, these commands help diagnose the problem:

# Check mail queue status (if Postfix is running)
postqueue -p

# Verify cron job configurations
crontab -l
ls -la /etc/cron.*

Remember that log files provide crucial clues:

tail -f /var/log/maillog
grep cron /var/log/messages