gowthamtr has asked for the wisdom of the Perl Monks concerning the following question:

I have a Mbox folder containing around 6000 mails. All these mails are from different emails-ids.

I have an email account which processes all the emails that it receives.

My task is to send all the mails in the Mbox format one by one to that email account with exactly the same content i.e without changing the From, To, Subject etc fields, so that all those emails are processed.

With which modules is it possible to do the task?
Is 'sendmail' useful in this case? If so how?

Replies are listed 'Best First'.
Re: Resend Email from Mbox format
by fenLisesi (Priest) on Feb 27, 2007 at 08:56 UTC
Re: Resend Email from Mbox format
by jettero (Monsignor) on Feb 27, 2007 at 12:18 UTC

    You may find Mail::Box::Mbox to be of some assistance as well.

    use strict; use Mail::Box::Mbox; my $input = Mail::Box::Mbox->new(folder=>$ifile) or die; for my $msg ($input->messages) { print "[$ifile] message subject: ", $msg->subject, " sender: ", $m +sg->sender, "\n"; } $input->close;

    -Paul

      last line:
      $input->close();
      
Re: Resend Email from Mbox format
by kyle (Abbot) on Feb 27, 2007 at 12:02 UTC

    I did something like this a little over a year ago with Net::SMTP doing the deliveries. If I were writing this today, it would probably be a bit different, but here's what I had back then:

    # $from is to be the envelope sender # $msg is the full text of the message, headers and all # (everything after the initial 'From ' line in the mbox sub attempt_delivery { my ( $from, $msg ) = @_; my $smtp; my $success; my $sleepy = 1; while ( ! ( $smtp = Net::SMTP->new('smtp.example.com') ) ) { print "Sleeping $sleepy...\n"; sleep( $sleepy ); $sleepy *= 2; $sleepy = 60 if ( $sleepy > 60 ); } if ( ! $smtp->mail( $from ) ) { $smtp->quit(); return 0; } # in my script, $to is a global variable if ( ! $smtp->to( $to ) ) { $smtp->quit(); return 0; } if ( ! $smtp->data() ) { $smtp->quit(); return 0; } if ( ! $smtp->datasend( $msg ) ) { $smtp->quit(); return 0; } if ( ! $smtp->dataend() ) { $smtp->quit(); return 0; } if ( ! $smtp->quit() ) { return 0; } return 1; }

    I was parsing through my mbox files by hand, mostly because they were mangled in various unseemly ways. If yours are pristine, you'll probably want to check out Email::Folder::Mbox or Mail::Mbox::MessageParser or something. CPAN has many candidates.