Author Topic: Mail delivery failed: returning message to sender  (Read 142 times)

Offline rdksm

  • Newbie
  • *
  • Posts: 1
Mail delivery failed: returning message to sender
« on: February 01, 2020, 04:43:39 PM »
I use this Perl script for mailing:

Code: [Select]
#!/usr/bin/perl
 
#use MIME::QuotedPrint;
use MIME::Base64;
 
$|=1;
*STDERR=*STDOUT;
 
$letter='';
 
$r=open(LET,"letter");
print "letter: \$r=$r\n$!\n" if !$r;
 
$from=<LET>;
$fromN=$1 if $from=~s/(^[^<]*?)\s*</</;
exit print "Не найден <адрес отправителя в первой строке letter>\n" if $from!~s/^<([^@]+@[^@]+)>\n*$/$1/;;
$fromN=~s/\s+$//;
$fromN=encode_base64($fromN);
$fromN=~s/\n//;
$From="=?UTF-8?B?$fromN?= <$from>\n";
 
$Subj=<LET>;
 
while(<LET>) {$letter.=$_}
close LET;
 
$r=open(ADDR,"addr");
print "addr: \$r=$r\n$!\n" if !$r;
$cnt=0;
while(<ADDR>) {
 my $em='';
 $cnt++;
 s/\s+$//;
 $name=$_;
 $em=$cnt.": Имя не найдено\n" if $name eq '';
#print length($name).": $name=\n$em\n"; exit;
 $fname=(split /\s+/,$name)[0];
 $addr=<ADDR>; $cnt++;
 $addr=~s/\s+$//;
 $em.=$cnt.": Адрес не найден\n" if $addr eq '';
 $em.=$cnt.": Неправильный адрес [$addr]\n" if $addr!~/^[^@]+@[^@]+$/;
 if($em){ print $em; exit }
 $foo=<ADDR>; $cnt++;
 my $let=$letter;
 $let=~s/%%%/$fname/;
 my $psubj=$Subj;
 $psubj=~s/%%%/$fname/;
 $psubj=encode_base64($psubj);
 $psubj=~s/\n//g;
 $psubj='=?UTF-8?B?'.$psubj."?=\n";
 
 my $mailprog="/usr/sbin/sendmail";
 $r=open(MAIL,"|$mailprog -t");
 print "sendmail: \$r=$r\n$!\n" if !$r;
 
 my $to='=?UTF-8?B?'.encode_base64($name)."?= <$addr>\n";
 $to=~s/\n//;
 my $letlen=length($let);
 print MAIL "MIME-Version: 1.0\n";
 print MAIL "To: $to";
 print MAIL "From: $From";
 print MAIL "Content-Type: text/plain; charset=UTF-8\n";
 print MAIL "Reply-To: $From";
 print MAIL "Return-Path: $from\n";
 print MAIL "Subject: $psubj";
 print MAIL "Content-Length: $letlen\n";
 print MAIL "\n$let";
 close MAIL;
 
 print "To: $name <$addr>\n";
 sleep(6)
}
close ADDR;
Добавлено через 5 минут

I would like dead letter notifications ("Mail delivery failed: returning message to sender") to be delivered to my address (ie, admin@mydomain.com).
Please advice how this is possible to solve?
Thank you :)