The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resending Default Address Mailbox Email

Discussion in 'E-mail Discussions' started by RequieM, Jul 21, 2014.

  1. RequieM

    RequieM Registered

    Joined:
    Jul 21, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    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.
     
  2. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    Once the email is delivered to the inbox, you can't re-queue it. You would need to either 1) copy the mail files to the remote mail server, if stores email in a maildir format, or 2) manually re-forward the email
     
  3. RequieM

    RequieM Registered

    Joined:
    Jul 21, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    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 .
     

    Attached Files:

  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page