When your primary mail server goes down, Postfix automatically queues messages on your backup server. By default, Postfix follows these retry intervals:
Initial delay: 300 seconds (5 minutes) Maximal delay: 4000 seconds (~1.1 hours) Backoff scheme: Doubles after each attempt
Method 1: Using postqueue command
# Flush entire queue: sudo postqueue -f # Flush specific queue ID: sudo postqueue -i 7D9B533002A
Method 2: Using sendmail command
# Process all deferred mail: sudo sendmail -q # Process specific queue: sudo sendmail -q -v deferred
# View queue contents: postqueue -p # Check deferred queue specifically: mailq | grep deferred
For permanent configuration changes, edit /etc/postfix/main.cf
:
# Reduce initial retry delay minimal_backoff_time = 60s # Set maximum retry attempts maximal_queue_lifetime = 5d # Increase simultaneous delivery attempts default_destination_concurrency_limit = 20
Create a cron job for periodic flushing:
# Add to crontab -e */5 * * * * /usr/sbin/postqueue -f
Or use a more sophisticated script that checks primary server availability first:
#!/bin/bash PRIMARY_SERVER="mail.example.com" if ping -c 1 $PRIMARY_SERVER &> /dev/null then /usr/sbin/postqueue -f fi
If messages still won't deliver:
# Check mail logs: tail -f /var/log/mail.log # Verify Postfix service status: postfix status # Test DNS resolution for target domain: dig MX example.com
When Postfix encounters delivery failures (like when your primary MX server is down), it implements an exponential backoff algorithm. This means:
- First retry after ~15 minutes
- Second retry after ~30 minutes
- Subsequent retries with increasing intervals
The most effective way to force immediate retry attempts is:
sudo postqueue -f
This signals Postfix to attempt delivery of all queued messages immediately, bypassing the scheduled retry times.
For more granular control:
# Process only deferred queue sudo postqueue -p | grep deferred | awk '{ print $1 }' | postsuper -r - # Process specific message by queue ID sudo postcat -q ABC123DEF456 | postfix sendmail -G -i
If postqueue -f
doesn't result in deliveries:
- Check mail logs:
tail -f /var/log/mail.log
- Verify Postfix is running:
sudo postfix status
- Test connectivity to destination:
telnet target.server 25
For regular monitoring, consider this bash script:
#!/bin/bash QUEUE=$(postqueue -p | grep -c '^[A-Z0-9]') if [ "$QUEUE" -gt 10 ]; then logger "High mail queue detected ($QUEUE messages), forcing flush" postqueue -f fi