With sendmail, how would you send all outgoing mail to /dev/null or just prevent email from being queued up or sent at all?

On a development nagios box I want prevent sending of mail so that notifications don't go out. Stopping outbound mail will allow me to test the nagios config as is and prevent spurious notifications.

  • Removed solaris tag, as the question, and the solution isn't OS specific at all. – Steve Schnepp Dec 13 '11 at 9:38
up vote 8 down vote accepted

I did this on my development box by disabling sendmail completely and then having a simple perl script listen on the SMTP port and dump the emails into a directory. I'm sure it's possible to do with the sendmail configuration, but the perl script was much easier. Here's it stripped down to the essentials:

#!/usr/bin/perl -w 
use Net::SMTP::Server; 
use Net::SMTP::Server::Client; 

$server = new Net::SMTP::Server || die("$!\n"); 

while($conn = $server->accept()) { 
  my $client = new Net::SMTP::Server::Client($conn) || 
    die("Unable to handle client connection: $!\n"); 
  $client->process || next; 

  # Here's where you can write it out or just dump it. Set $filename to 
  # where you want to write it
  open(MAIL,"> $filename") || die "$filename: $1"; 
  print(MAIL "$client->{MSG}\n"); 
  close(MAIL); 
} 
  • This is an even better solution than I was thinking. Thanks. – cwebber Feb 23 '11 at 21:51
  • +1 What an elegant solution, I was about to ask the same question. – Kev Mar 27 '11 at 12:53

The following sends everything to /dev/null:

LOCAL_RULE_0
R$* < @ $* > $*       $#local $: bit-bucket

This assumes that in your /etc/aliases:

bit-bucket: /dev/null
  • Be careful not to just type this in -- there is a TAB between the two sides of the rule. – Erica Kane Apr 15 '16 at 13:32
  • What email system are you using and where do you add that rule? – teknopaul Jan 10 '17 at 16:53
  • Standard sendmail from sendmail.org. The rule gets added to sendmail.mc and then sendmail.cf is produced according to your OS / distribution's specifics. – adamo Jan 11 '17 at 8:49

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.