SuppressOutgoingMail: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (4 revisions imported)
(No difference)

Revision as of 15:37, 6 April 2016

Suppress All Outgoing Mail

Posted by Steve Turner, March 3, 2006.

This modification allows you to turn off ALL outgoing mail by using a new config variable. It is useful if you need to load tickets into a live system from a perl script (from a legacy system, for example) and you don't want RT to send mail for all the tickets you are loading.

All that's required is a new config variable (we called it $RT::MailSendingOff) and a minor mod to RT/lib/Action/SendEmail.pm.

If the config variable is true, no email will be sent by RT. Otherwise (config variable false or undef), mail will be sent as usual.

Typically on our live system we have this variable set to 0 in RT_SiteConfig.pm so that RT's mail continues to work as expected for our users. In our data load scripts we turn off outgoing email for the duration of the load by coding this:

$RT::MailSendingOff = 1;

The modification to SendEmail,pm is at the top of the SendMessage method:

sub SendMessage {
   my $self    = shift;
   my $MIMEObj = shift;

   my $msgid = $MIMEObj->head->get('Message-Id');
   chomp $msgid;

   # BEGIN MOD:
   # Do not send mail if the config says not to:
   if ($RT::MailSendingOff) {
       return (1);
   }
   # END MOD:

   $RT::Logger->info( $msgid . " #"
       . $self->TicketObj->id . "/"
       . $self->TransactionObj->id
       . " - Scrip "
       . $self->ScripObj->id . " "
       . $self->ScripObj->Description );

Suppress Some Outgoing Mail

Posted by Chris Adams, Jan 31, 2008

The easiest way to suppress outgoing mail to a particular user (eg. noreply@example.com) is to remove the e-mail address from the autocreated user.  As long as their username is the same as their e-mail address, that user will still be used for incoming messages, but outgoing messages won't be sent.

If you want finer-grained control, this modification allows you to specify certain addresses which will be removed when RT generates email by adding something like this to RT_SiteConfig.pm:

Set($SquelchList, 'root@example.edu,www-data@example.edu,nobody@example.edu');

The mod applies to =RT/Action/SendEmail.pm= just before it uses @blacklist to yank recipients - here's the patch against the Debian 3.6.1-4 package:

--- SendEmail.pm	2008-01-31 11:51:15.344883000 -0800
+++ /usr/share/request-tracker3.6/lib/RT/Action/SendEmail.pm	2008-01-31 11:54:30.000000000 -0800
@@ -593,6 +593,15 @@
         push @blacklist, $attribute->Content;
     }

+		# BEGIN SNL Modification: global squelch list
+		#	This allows you to add a variable to RT_SiteConfig.pm containing addresses which will always be squelched:
+		# Set($SquelchList, 'root@example.edu,www-data@example.edu,nobody@example.edu');
+		if ($RT::SquelchList) {
+      $RT::Logger->debug("Using global squelch list: $RT::SquelchList\n");
+			push @blacklist, split(/,/, $RT::SquelchList);
+		}
+		# END SNL Modification: global squelch list
+
     # Cycle through the people we're sending to and pull out anyone on the
     # system blacklist

Suppress Some Outgoing Mail by Regular Expression

Posted by Michael Brader April 22, 2009.

This is similar to the above but removes the addresses if they match a regular expression. In RT_SiteConfig.pm:

Set($SquelchRegexp, qr/noreply|sell-it-support|spam_master/);

The patch to to =RT/Action/SendEmail.pm= (from 3.8.2) checks each address against the regexp after the blacklist check

--- local/lib/RT/Action/SendEmail.pm    2009-04-22 02:56:09.000000000 +0000
+++ lib/RT/Action/SendEmail.pm  2009-01-12 23:18:46.000000000 +0000
@@ -826,11 +826,6 @@
                 $RT::Logger->info( $msgid . "$addr was blacklisted for outbound mail on this transaction. Skipping");
                 next;
             }
-           # Global Squelch Regexp
-           if ($RT::SquelchRegexp and $addr =~ /$RT::SquelchRegexp/) {
-                $RT::Logger->info( $msgid . "$addr was squelched based on \$RT::SquelchRegexp in RT_SiteConfig.pm. Skipping");
-                next;
-           }
             push @addrs, $addr;
         }
         @{ $self->{$type} } = @addrs;

Suppress an email address by using a Scrip

If you have a need for certain email addresses to be suppressed in a particular queue (for example, tickets coming in from an automated system which uses an address which does not accept replies), you can create a Scrip to squelch the address. Use the On Create condition, and a User Defined action. The Prepare should be simply:

1;

and the Commit code should be something like:

return 1 unless $self->TicketObj->IsWatcher( Type => 'Requestor',
                                             Email => 'noreply@example.com' );
$self->TicketObj->SquelchMailTo('noreply@example.com');
return 1;