How to Redirect All Outbound Sendmail Messages to /dev/null for Development Environments


2 views

When working on development systems like Nagios monitoring servers, accidentally sending real email notifications can cause unnecessary panic among team members or customers. The ideal solution is to intercept all outgoing messages while maintaining the existing email infrastructure for testing purposes.

Sendmail provides several approaches to handle this scenario. The most straightforward method uses the discard mailer:

# Add to your sendmail.mc configuration:
define(MAIL_HUB', local:devnull')dnl
define(LOCAL_MAILER_ARGS', mail -d $u')dnl

For systems where you want complete message suppression:

# In sendmail.mc:
define(MAIL_HUB', procmail -Y -a $h -d $u')dnl
define(LOCAL_MAILER_PATH', /usr/bin/procmail')dnl
define(LOCAL_MAILER_ARGS', procmail -Y -a $h -d $u')dnl

Then create a ~/.procmailrc with:

:0
* ^To:.*
/dev/null

After making changes to sendmail.mc, always:

# Rebuild the configuration:
m4 sendmail.mc > sendmail.cf
# Restart sendmail:
service sendmail restart
# Test with:
echo "Test message" | mail -s "Test" user@example.com

Remember that these changes should only be made on development systems. For production Nagios servers, consider implementing proper notification controls through:

  • Nagios' built-in maintenance mode
  • Notification time periods
  • Contact group filtering

When working with monitoring systems like Nagios in development environments, sending actual email notifications can cause several issues:

  • Spamming real users with test notifications
  • Filling up mail queues with unnecessary messages
  • Potential security concerns with sending test data
  • Wasting system resources on mail processing

There are several ways to prevent Sendmail from actually delivering messages:

Method 1: Using a nullmailer

Modify your sendmail.mc file to use a null mailer:

define(MAIL_HUB', local:')
define(LOCAL_MAILER_PATH', /bin/true')
define(LOCAL_MAILER_ARGS', mail -d $u')

Then rebuild your sendmail.cf file and restart Sendmail:

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
service sendmail restart

Method 2: Direct Output to /dev/null

Edit your sendmail configuration to pipe all mail to /dev/null:

FEATURE(nullclient', localhost')dnl
define(confDELIVERY_MODE', q')dnl
define(LOCAL_MAILER_PATH', /bin/true')dnl
define(LOCAL_MAILER_FLAGS', ')dnl
define(LOCAL_MAILER_ARGS', ')dnl

After making these changes, verify they work as expected:

echo "Test message" | sendmail user@example.com

Check that:

  • No message appears in the mail queue (use mailq command)
  • No actual email is received
  • No errors in mail logs (/var/log/maillog)

For Nagios testing, you might want to:

  1. Keep the full notification logic working
  2. Maintain all logging and alert generation
  3. Only suppress the actual email delivery

This approach allows you to:

  • Verify notification thresholds are working
  • Test escalation policies
  • Check contact group assignments

For more advanced testing, consider setting up a local SMTP server that captures but doesn't deliver messages:

# Install Python's debugging SMTP server
python -m smtpd -n -c DebuggingServer localhost:25

Then configure sendmail to use this server as a smarthost:

define(SMART_HOST', localhost')dnl