[rt-users] Sorting e-mail into queues automatically using procmail

Nicôle Layne nlayne at telebarbados.com
Thu Aug 26 19:39:24 EDT 2010


Just letting everyone know that I got it to work.

Here are my config and script files in case this can help anyone.

/home/rt/.procmailrc

#Preliminaries
	SHELL=/bin/sh               #Use the Bourne shell (check your path!)
	MAILDIR="/var/mail/rt/"
	LOGFILE="/home/rt/proc.log"
	LOG="--- Logging ${LOGFILE} for ${LOGNAME}, "
	VERBOSE=yes
	MAILDOMAIN="rt.mydomain.com"
#Made no changes to the default rt-mailgate file
	RT_MAILGATE="/opt/rt3/bin/rt-mailgate"
	RT_URL="http://rt.mydomain.com/"
	LOGABSTRACT=all
	# the following line extracts the recipient from Received-headers.
	# Simply using the To: does not work, as tickets are often created
	# by sending a CC/BCC to RT
	TO=`formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'`
	QUEUE=`echo $TO| $HOME/get_queue.pl`
	ACTION=`echo $TO| $HOME/get_action.pl`
	:0 h b w 
	|/usr/bin/perl $RT_MAILGATE --queue $QUEUE --action $ACTION --url $RT_URL

/root/get_action.pl

#!/usr/bin/env perl

	@arr = <STDIN>;
	$action = "correspond";
	foreach (@arr) {
		if (/\s*.*<([^@]+)-comment at .*>/g) {
			$action = "comment";
		} else { 
			if (/\s*([^@]+)-comment at .*/g) {
				$action = "comment";
			} 
		}
	}
	print "$action";

/root/get_queue.pl

#!/usr/bin/env perl

	@arr = <STDIN>;
	$queue = 'general';
	foreach (@arr) {
		if (/\s*.*<([^@]+)@.*>/g) {
			$queue = $1;
			} else { 
				if (/\s*([^@]+)@.*/g) {
					$queue= $1;
				} 
			}
		}
	if ($queue =~ /(.*)-comment/)
	{
		$queue = $1;
	}
print "$queue";

/opt/rt3/etc

Set($rtname , "RT.mydomain.com");
Set($Organization , "rt.mydomain.com");
Set($Timezone , 'US/Eastern');
Set($DatabaseType , 'mysql');
Set($DatabaseHost   , 'localhost');
Set($DatabaseRTHost , 'localhost');
Set($DatabasePort , '');
Set($DatabaseUser , 'rt');
Set($DatabasePassword , 'whateveryoulike');
Set($OwnerEmail , 'root');
Set($RTAddressRegexp , '^rt\@rt.mydomain.com$');
Set($ValidateUserEmailAddresses, 1);
Set($CorrespondAddress , 'no-reply at rt.mydomain.com');
Set($CommentAddress , 'no-reply at rt.mydomain.com');
Set( $WebDomain, 'rt.mydomain.com' );
Set($WebPath, "");
Set($CanonicalizeRedirectURLs, 1);
Set($LogToSyslog , 'info');
Set($UnsafeEmailCommands,1);
Set($LogToSyslog, "debug");
Set(@Plugins,qw(RT::FM));

1;


Kind regards,
Nicôle

-----Original Message-----
From: Nicôle Layne 
Sent: Thursday, August 26, 2010 11:19 AM
To: rt-users at lists.bestpractical.com
Subject: RE: [rt-users] Sorting e-mail into queues automatically using procmail

Update (still not working):

I believe main error to be this, although the mailgate file is there and contains the default content.

Can't open perl script "/opt/rt3/bin/rt-mailgate
": No such file or directory
procmail: Error while writing to "/usr/bin/perl"
procmail: Program failure (2) of "/usr/bin/perl"
procmail: Assigning "LASTFOLDER=/usr/bin/perl /opt/rt3/bin/rt-mailgate
 --queue general
 --action correspond
 --url http://rt.mydomain.com/

Thanks for your suggestion Stucki.

Here's what the file currently looks like, not seeing any funny characters or spaces from cmd line (all the # are from me testing different portions, will clean up once I get it working).

> more /home/rt/.procmailrc
::::::::::::::
/home/rt/.procmailrc
::::::::::::::
#Preliminaries
	SHELL=/bin/sh               #Use the Bourne shell (check your path!)
	#MAILDIR=${HOME}        #First check what your mail directory is!
	MAILDIR="/var/mail/rt/"
	#LOGFILE=${MAILDIR}/procmail.log
	LOGFILE="/home/rt/procmail_log.log"
	LOG="--- Logging ${LOGFILE} for ${LOGNAME}, "
	VERBOSE=yes
	MAILDOMAIN="rt.mydomain.com"
	RT_MAILGATE="/opt/rt3/bin/rt-mailgate"
	#RT_MAILGATE="/usr/local/bin/rt-mailgate"
	RT_URL="http://rt.mydomain.com/"

	LOGABSTRACT=all
	#QUEUE=`echo $TO| $HOME/get_queue.pl`
	#ACTION=`echo $TO| $HOME/get_action.pl`

	#:0
	#{
	# the following line extracts the recipient from Received-headers.
	# Simply using the To: does not work, as tickets are often created
	# by sending a CC/BCC to RT
	#TO=`formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'`
	TO=`formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'`
	QUEUE=`echo $TO| $HOME/get_queue.pl`
	ACTION=`echo $TO| $HOME/get_action.pl`
	:0 h b w 
	|/usr/bin/perl $RT_MAILGATE --queue $QUEUE --action $ACTION --url $RT_URL
	#}

I made some other changes since my original e-mail and here is an output of the logs:

--- Logging /home/rt/proc.log
 for rt, 
procmail: [18543] Thu Aug 26 11:08:41 2010
procmail: Assigning "MAILDOMAIN=rt.mydomain.com
"
procmail: Assigning "RT_MAILGATE=/opt/rt3/bin/rt-mailgate
"
procmail: Assigning "RT_URL=http://rt.mydomain.com/
"
procmail: Assigning "LOGABSTRACT=all
"
procmail: Executing "formail -c -xReceived: |grep $MAILDOMAIN |sed -e 's/.*for *<*\(.*\)>* *;.*$/\1/'"
procmail: Assigning "TO=
"
procmail: Executing "echo $TO| $HOME/get_queue.pl"
procmail: Assigning "QUEUE=general
"
procmail: Executing "echo $TO| $HOME/get_action.pl"
procmail: Assigning "ACTION=correspond
"
procmail: Skipped "
"
procmail: Executing "/usr/bin/perl,/opt/rt3/bin/rt-mailgate
,--queue,general
,--action,correspond
,--url,http://rt.mydomain.com/

"
Can't open perl script "/opt/rt3/bin/rt-mailgate
": No such file or directory
procmail: Error while writing to "/usr/bin/perl"
procmail: Program failure (2) of "/usr/bin/perl"
procmail: Assigning "LASTFOLDER=/usr/bin/perl /opt/rt3/bin/rt-mailgate
 --queue general
 --action correspond
 --url http://rt.mydomain.com/

"
procmail: Locking "/var/mail/rt.lock"
procmail: Assigning "LASTFOLDER=/var/mail/rt"
procmail: Opening "/var/mail/rt"
procmail: Acquiring kernel-lock
procmail: Unlocking "/var/mail/rt.lock"
procmail: Notified comsat: "rt at 85426:/var/mail/rt"
>From me at mydomain.com  Thu Aug 26 11:08:41 2010
 Subject: Testing to internal
  Folder: /var/mail/rt							   6147

Syslog:
Aug 26 11:08:41 RT postfix/smtpd[18537]: connect from [local Exchange server]
Aug 26 11:08:41 RT postfix/smtpd[18537]: 599F948096: client=[local Exchange server]
Aug 26 11:08:41 RT postfix/cleanup[18540]: 599F948096: message-id=<4C137E3BA6DB4A4291596A118437D8E5B3F295 at Exchange_server.mydomain.com>
Aug 26 11:08:41 RT postfix/qmgr[5063]: 599F948096: from=<nlayne at mydomain.com>, size=6163, nrcpt=1 (queue active)
Aug 26 11:08:41 RT postfix/smtpd[18537]: disconnect from [local Exchange server]
Aug 26 11:08:41 RT postfix/local[18542]: 599F948096: to=<rt at RT.mydomain.com>, orig_to=<internal at rt.mydomain.com>, relay=local, delay=0.29, delays=0.1/0.03/0/0.16, dsn=2.0.0, status=sent (delivered to command: /usr/bin/procmail)
Aug 26 11:08:41 RT postfix/cleanup[18540]: 984B748098: message-id=<20100826150841.984B748098 at RT.mydomain.com>
Aug 26 11:08:41 RT postfix/bounce[18541]: 599F948096: sender delivery status notification: 984B748098
Aug 26 11:08:41 RT postfix/qmgr[5063]: 599F948096: removed
Aug 26 11:08:41 RT postfix/qmgr[5063]: 984B748098: from=<>, size=2642, nrcpt=1 (queue active)
Aug 26 11:08:50 RT postfix/smtp[18558]: 984B748098: to=<nlayne at mydomain.com>, relay=10.0.0.44[10.0.0.44]:25, delay=8.9, delays=0.02/0.04/0.02/8.8, dsn=2.6.0, status=sent (250 2.6.0  <20100826150841.984B748098 at RT.mydomain.com> Queued mail for delivery)
Aug 26 11:08:50 RT postfix/qmgr[5063]: 984B748098: removed

Kind regards,
Nicôle

-----Original Message-----
From: Chr. von Stuckrad [mailto:stucki at mi.fu-berlin.de] 
Sent: Thursday, August 26, 2010 5:12 AM
To: Nicôle Layne
Subject: Re: [rt-users] Sorting e-mail into queues automatically usingprocmail

Hi!

Seeing the strange "somethimg<NEWLINE>" pattern in the log lines
and seeing the definitley broken single '{' for 'LASTFOLDER'
reminds me of the time, when one of our Users edited his .procmailrc
with an WINDOWS-Editor inserting '<CarriageReturn><Newline>' where
procmail only understands '<newline>' for the line-endings.

Lots of strange things then happened, because listings do not
show the difference, but the 'character' was used for Filenames
and such...

So you may look into your procmailrc with a tool showing 'really
everything' (UNIX: e.g.'xxd') to check this.
Or load the file into an editor which can explicitely write it
with 'only newline' == UNIX-line-end.

May be this helps ... ?

Stucki


On Tue, 24 Aug 2010, Nicôle Layne wrote:

> --- Logging /home/rt/procmail_log.log
... ... ...
> procmail: Assigning "LASTFOLDER={
> 
> "
> 
> procmail: Opening "{
> 
> "





More information about the rt-users mailing list