2 From mdm@internet-tools.com Mon Mar 30 09:53:15 1998
3 Date: Fri, 27 Mar 1998 22:09:36 -0600
4 From: mark david mcCreary <mdm@internet-tools.com>
5 To: exim-users@exim.org
6 Subject: [EXIM] gadget to parse log file and generate bounce message
8 These steps can process exim log files, and generate a bounce message
9 back to mailing lists, thus clearing the bad address off the list.
11 Bounce message come in a couple of flavors. First of all, it could
12 bounce before the message even got there. They just reply with an
13 SMTP code of 5xx, such as 550 - User Unknown. Juno.com does it this
16 Or they could accept the message, and then later on realize that the
17 user is unknown, and email back a bounce message. Aol.com does it
20 This gadget will help remove bad addresses from juno.com, and similiar
21 mail hosts. Since there is no bounce message, the information must be
22 gotten from the exim log (typically called exim_mainlog).
24 This works ok with the Smartlist Mailing List Manager.
29 1) Use Eximstats to generate error only report, and mail to special
32 Put this in your crontab file
34 54 23 * * * root /usr/local/exim/bin/eximstats -nt -h0 -q0
35 -nr -t0 /var/log/exim/exim_mainlog 2>&1 | /bin/mail -s 'exim errors' bouncer
39 It generates a report like this
41 1 Joe@aol.net <jokes@mail.domain.com>: unrouteable mail
44 which means that the error occured 1 time, joe@aol.net was the mailing
45 list subscriber, and jokes was the mailing list.
47 2) Procmail recipe massages headers, and passes body of message to
48 Perl program. Handle email sent to bouncer address.
51 # The mail-list.com front-end for Smartlist Mailing Lists
53 # Copyright (c) 1998 Internet Tools, Inc.
55 # This program is free software; you can redistribute it
57 # it under the terms of the GNU General Public License as
59 # the Free Software Foundation; either version 2 of the
61 # (at your option) any later version.
64 # Bounce Error Routine
66 # Reads report of errors generated by Eximstats and creates and sends
67 # bounce message back to appropriate list
69 # Calls Perl program bouncer.pl to accomplish the bulk of the work
71 PATH=.:/home/ftp/discuss/.bin:/bin:/usr/bin:/usr/local/bin:/usr/sbin:$PATH
\r SHE
76 LOGFILE=$HOME/procmailog
79 DOMAIN=domain.com # the common domain for all the lists
80 SUBDOMAIN=`hostname` # the fully qualified hostname
82 # save a copy of all incoming files to an existing directory
88 SENDER = `formail -rtzx To:`
89 SUBJECT = `formail -zxSubject:`
90 TODAY = `date "+%Y-%m-%d %T"`
94 | echo -e $TODAY "\t" $SENDER "\t" $SUBJECT >> log-bouncer
97 # filter the email message
98 # set up the headers for the perl program
101 | formail -I"Subject: Bounce from Bouncer" \
102 -I"From: mailer-daemon@localhost"
105 # pass email message to perl program
106 # which will send out 1 email message for each error line in the
114 3) Perl program parses report, grabbing bad email addresses, and
115 sending in a bounce message.
119 # The mail-list.com front-end for Smartlist Mailing Lists
121 # Copyright (c) 1998 Internet Tools, Inc.
123 # This program is free software; you can redistribute it
125 # it under the terms of the GNU General Public License as
127 # the Free Software Foundation; either version 2 of the
129 # (at your option) any later version.
134 # This program will generate bounce messages, and send them to the
135 # appropriate list-request address.
137 # This program is invoked by a Procmail recipe. The body of the email
138 # message is an error report produced by Eximstats.
140 # The error report has a specific format of error messages, which
143 # 1 u2pino@telcel.net.ve <chistes@mail.domain.com>
145 # From which the first email address is the bad address, and the
147 # address is the list address. Which can easily be transformed into
148 # the list-request address.
150 # This program uses the Perl Module Mail::Internet to send each
158 chop(my $Date = `date "+%Y-%m-%d %T"`);
160 my $error_ind = ' \d '; # all error lines start
162 my $bounce_body = ' 550 '; # 550 is SMTP error code for user
164 open(LOG,">>/tmp/bouncer.log") || die(" Could not open bouncer.log
167 $ENV{'SMTPHOSTS'} = 'localhost';
169 my $mesg = new Mail::Internet \*STDIN;
171 # look at mail headers, and grab the data
173 my $from = $mesg->head->get('From'); chop($from);
174 my $subject = $mesg->head->get('Subject'); chop($subject);
178 my $body = $mesg->body();
179 map {chop($_)} @$body;
181 # @commands is an array of each line in the message body.
183 my @commands = @$body;
188 foreach $command (@commands) {
190 next if $command =~ m/^\s*$/; # skip
193 unless ($command =~ m/^$error_ind/) {
197 @tokens = split(/\s+/, $command); # put each word
198 into a seperate array cell
200 my $bad_address = $tokens[2]; # bad
201 address that caused the list problems
203 my $list_address = $tokens[3]; # list address that
206 $list_address =~ s/<//; #
207 strip < symbol from address
208 $list_address =~ s/>//; #
209 strip > symbol from address
210 $list_address =~ s/://; #
211 strip colon symbol from address
212 $list_address =~ s/\@/-request\@/; # add request onto
215 unless ($bad_address =~ m/\@/) {
219 unless ($list_address =~ m/\@/) {
223 # make the body of the message a simple bounce message that
226 my $message_body = $bounce_body . "<" . $bad_address . ">"
229 my $new_mesg = new Mail::Internet(
231 'Body' => [$message_body]
234 # this is who the mail is directed to via SMTP;
236 $ENV{MAILADDRESS} = $from;
238 # these are the addresses placed in the header block of the
241 $new_mesg->head()->add('From', $from);
242 $new_mesg->head()->add('To', $list_address);
243 $new_mesg->head()->add('Subject', $subject);
245 # $new_mesg->print_header(\*LOG);
246 # $new_mesg->print_body(\*LOG);
248 print LOG "$Date\t$list_address\t$bad_address\n";
250 my @recips = $new_mesg->smtpsend;
252 unless (@recips > 0) {
253 print LOG "Failed to deliver
254 ($from,$list_address,$message_body) \n";
261 4) Mailing list software unsubscribes bad address.
267 You have Procmail installed. Preferably the latest version.
269 Your exim configuration file receives incoming mail for localhost ip
270 address. For example,
272 local_domains = "@:domain.com:[127.0.0.1]"
274 You have Eximstats, which is a Perl program to report on the exim
275 mainlog, that comes with Exim as standard equipment.
277 You have the Perl Mailtools modules installed. This module takes care
278 of sending via SMTP interchange a mail message to the list request
281 I will be happy to take corrections, updates, or additions via private
282 email (mdm@internet-tools.com).
289 Internet Tools, Inc. 1436 West Gray #438
290 mdm@internet-tools.com Houston, Texas 77019
291 http://www.internet-tools.com 713.627.9600
296 *** Exim information can be found at http://www.exim.org/ ***