Skip to content
Nigel Metheringham edited this page Nov 25, 2012 · 1 revision

Script to re-deliver a message to exim (by John Jetmoreon exim-users, but not in the archive)

Copy and paste following content (after read if there are any dangeous line on this perl script, since here is a public Wiki) to redeliver.pl file and run it without root privileges:

$ perl redeliver.pl MAILBOX

Where MAILBOX is MAILBOX file to proccess.

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);
}

Give all messages in queue a new delivery attempt. Causes significant load!

exim -bpru | exiqsumm  | sed '1,4d;$d;s/^.*\ \(.[^\ ]*$\)/\1/' | xargs -P 10 -n 1 exim -v -qqR

(posted on exim-users by Tamas TEVESZ)


Another way to force a queue delivery attempt:

mailq | grep '^..[dhm]'  | awk '{print $3}' | xargs -P 4 -n 1 exim -M
Clone this wiki locally