Resending Default Address Mailbox Email

RequieM

Registered
Jul 21, 2014
2
0
1
cPanel Access Level
Root Administrator
Hi There,

We had a problem with an MX record on one of our alias domains and all email that should have been going to a remote mail exchanger has ended up in the default mailbox (around 400 emails).

Is there any way to resend or forward all of this mail in the default address mailbox to the "Envelope-To" address automatically?

Or am I doomed to do this manually :(.


Thanks in Advance.
 

RequieM

Registered
Jul 21, 2014
2
0
1
cPanel Access Level
Root Administrator
Hey Vanessa,

Thanks for the response. I did a little digging whilst I was waiting and found an Exim re-queue Perl script here: https://github.com/Exim/exim/wiki/Redeliver.

I combined this with a little shell script rather than modifying the Perl script to iterate through all files in the cur/ mail folder:

Code:
#!/bin/bash
FILES=/home/acccoutname/mail/cur/*
for f in $FILES
do
 echo "Processing $f email..."
 perl redeliver.pl "$f"
done
And the corresponding redeliver.pl Perl script:

Code:
my $file = shift || die "need file\n";
my $gto  = shift; # global to.  if present, override other per-email decision
my $msg  = '';
my $to   = '';
my $from = '';

open(I, "<$file") || die "Can't open $file\n";
while (<I>) {
  if (/^From /) {
    if ($msg) {
      if ($to && $from) {
        do_mail($from, $to, $msg);
      } else {
        print STDERR "have a message but no recips\n";
      }
    } else {
      print STDERR "saw From w/ no message\n";
    }
    $msg  = '';
    $from = '';
    $to   = '';
  } elsif (/^Return-path:\s*<(.*)>$/) {
    $from = $1;
  } elsif (/^Envelope-to:\s*(\S+)\s*$/) {
    $to = $1;
  } elsif (/^Delivery-date:\s*/) {
    ; # just ignore
  } else {
    $msg .= $_;
  }
}
close(I);

if ($msg && $to && $from) {
  do_mail($from, $to, $msg);
}

sub do_mail {
  my $f = shift;
  my $t = shift;
  my $m = shift;
  $t = $gto if ($gto);

  print "$f -> $t\n";
  #print "MAIL FROM:<$f>\nRCPT TO:<$t>\nDATA\n$m\n.\n";
  open(P, "|/usr/lib/sendmail -f $f $t") || warn "can't open sendmail: $!\n";
  print P $m, "\n.\n";
  close(P);
}
Both of these files are in the zip file attached. Nothing fancy but I hope this is of some use to anyone with the same problem .
 

Attachments