When dealing with multiple applications that send emails through an external mail transfer agent (MTA), service interruptions can cause significant operational issues. The need arises for a local queueing mechanism that can:
- Accept emails from internal applications
- Queue messages during external MTA outages
- Relay messages to the destination MTA when available
The most effective way to implement this is through sendmail's SMART_HOST
feature combined with proper queue management. Here's the core configuration strategy:
# In your sendmail.mc file: define(SMART_HOST', [external.mta.example.com]')dnl FEATURE(queuegroup')dnl FEATURE(greet_pause')dnl
1. Basic Relay Setup
# /etc/mail/sendmail.mc configuration: define(confQUEUE_LA', 5')dnl # Start queueing when load avg > 5 define(confMIN_QUEUE_AGE', 30m')dnl # Minimum time in queue before retry define(confTO_QUEUEWARN', 4h')dnl # Send delay notification after 4h define(SMART_HOST', smtp:[external.mta.example.com]')dnl
2. Queue Groups for Better Management
QUEUE_GROUP(relayq', P=/var/spool/mqueue/relay, R=2, I=1m')dnl QUEUE_GROUP(localq', P=/var/spool/mqueue/local')dnl define(confQUEUE_GROUP', relayq')dnl
3. Network Timeout Adjustments
define(confTO_CONNECT', 1m')dnl define(confTO_ICONNECT', 1m')dnl define(confTO_HELO', 5m')dnl define(confTO_MAIL', 10m')dnl
For your case where emails have arbitrary destination domains but come from a fixed internal domain, we can use mailertable:
# /etc/mail/mailertable . relay:[external.mta.example.com]
Then rebuild the mailertable database:
makemap hash /etc/mail/mailertable.db < /etc/mail/mailertable
After making these changes, remember to:
# Rebuild sendmail.cf m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf # Restart sendmail service sendmail restart # Test the configuration echo "Subject: Test" | sendmail -f support@company.com user@externaldomain.com
Regularly check your queue with:
mailq sendmail -bp sendmail -q -v # Process queue in verbose mode
For true high availability, consider setting up multiple external MTAs:
# In mailertable: . relay:[primary.mta.example.com],[backup1.mta.example.com],[backup2.mta.example.com]
Tune these parameters based on your mail volume:
define(confMAX_QUEUE_CHILDREN', 50')dnl define(confMAX_DAEMON_CHILDREN', 100')dnl define(confMIN_FREE_BLOCKS', 100')dnl
When dealing with mission-critical email delivery from multiple applications, implementing a local queueing mechanism becomes essential. The common pain point is external MTA outages causing application-level failures. Sendmail can serve as an effective buffer between your applications and the external mail infrastructure.
The most efficient approach involves using both SMART_HOST for outbound routing and queue management parameters:
# In sendmail.mc define(SMART_HOST', smtp.ext-mta.example.com')dnl define(confQUEUE_LA', 5')dnl # Queue when load avg > 5 define(confMIN_QUEUE_AGE', 30m')dnl # Retry interval define(confTO_QUEUEWARN', 4h')dnl # Warn after 4hrs in queue define(confTO_QUEUERETURN', 5d')dnl # Return undeliverable after 5 days
For more granular control over specific domains while maintaining the default relay:
# /etc/mail/mailertable .example.com esmtp:[ext-mta.example.com] backup.com esmtp:[secondary-mta.example.net]
Configure your queue runner for optimal performance:
# In sendmail.mc define(confDELIVERY_MODE', background')dnl define(confMAX_QUEUE_CHILDREN', 16')dnl define(confREFUSE_LA', 12')dnl # Reject new connections at LA 12
Essential commands for queue management:
# Force queue processing /usr/sbin/sendmail -q -v # Check queue status mailq # Test configuration sendmail -bt << EOF parse user@example.com EOF
When relaying through an external MTA, ensure proper authentication:
# In sendmail.mc define(confAUTH_MECHANISMS', EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl FEATURE(authinfo', hash /etc/mail/authinfo.db')dnl