#!/usr/bin/perl ######################################################################### ## This program reads RFC822 compliant mail message from stdin and then ## send this mail via smtp. The smtp server is specified via $smtp_server. ## This program can be called from a mailer like "mutt" as sendmail. ## ## ## may-25-2000 use Mail::Sendmail module to send via smtp. Mail::Mailer # does not work with more that 1 Cc or Bcc. -mm # # jul-13-2000 if a emply LF was in the mail, the delivery through qmail # was failing. Ref: http://cr.yp.to/docs/smtplf.html # now log the status of delivery. if there's a problem with # delivery it will exit with 1. -mm # # jul-14-200 changed in_reply_to var in .muttrc, so removing # In-Reply-To is not needed anymore. -mm ## ############################################################################# use strict; use Mail::Internet; use Mail::Sendmail; $|=1; ################globals##----- starts my $log="/home/muquit/Mail/mail.log"; # change my $smtp_server="xxx.xxx.xxx"; # change my $mail; my $body; my $head; my %headers=(); my $header; my @header_tags=(); my $mailer; my $msg_line=''; my %mailcfg=(); my $mda_tag="Mail::Internet Mail::Sendmail Sendmail +mmhack 1.1 on Linux"; my $rc; my $cc=''; my $bcc=''; my $date=''; ################globals##----- ends # set my custom MDA tag $mailcfg{'X-MDA'}="$mda_tag"; $mailcfg{message}=''; $mailcfg{smtp}=$smtp_server; # accumulate the mail in mail object $mail=new Mail::Internet []; # get the head object from the mail object $head=$mail->head(); # get the body array reference $body=$mail->body; # get all the header tags @header_tags=$head->tags(); foreach $header (@header_tags) { my $tmp=$head->get("$header"); chomp($tmp); # In-Reply-To created my mutt causes trouble if the mail is sent via # qmail. As the line contains a;, the module creates an empty LF. # look at: http://cr.yp.to/docs/smtplf.html # -- muquit@muqit.com, Jun-13-2000 # # well in mutt, I changed set in_reply_to="%i" so no need to remove it # here -- muquit@muquit.com, Jul-14-2000 ## next if ($header eq "In-Reply-To"); $headers{$header}=$tmp; $mailcfg{$header}=$tmp; } $cc=$headers{'Cc'}; $bcc=$headers{'Bcc'}; $date=localtime(); # log foreach $msg_line (@{$body}) { $mailcfg{message} .= $msg_line; } # send the mail via SMTP $rc=sendmail(%mailcfg); # open the log file open(FD,">>$log"); # if exits with an non-zero exit code, mutt will catch the error. if $rc is # 0, exit with 1 to tell mutt an error # muquit@muquit.com, Jun-13-2000 if (! $rc) { print STDOUT "$Mail::Sendmail::error\n"; print FD "XX In-Reply-To: $headers{'In-Reply-To'}\n"; close(FD); exit(1); } else { print FD "To: $headers{'To'}\n"; print FD "Date: $date\n"; print FD "Subject: $headers{'Subject'}\n"; print FD "Cc: $cc\n" if $cc; print FD "Bcc: $bcc\n" if $bcc; print FD "\n"; close(FD); exit(0); }