Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: forwarding emails with perl??

by gellyfish (Monsignor)
on Aug 03, 2005 at 17:55 UTC ( [id://480582]=note: print w/replies, xml ) Need Help??


in reply to forwarding emails with perl??

You can do this with Email::Folder and Email::Send quite easily:

use strict; use warnings; + use Email::Send; use Email::Folder; + my %received; my $box = Email::Folder->new('/home/jonathan/mail/Recruiters/'); while ( my $mail = $box->next_message ) { + $mail->header_set('To','jonathan@localhost'); send SMTP => $mail->as_string(), 'localhost'; }
Of course fixing some of the values as appropriate.

/J\

Replies are listed 'Best First'.
Re^2: forwarding emails with perl??
by chrisj0 (Acolyte) on Aug 03, 2005 at 18:10 UTC
    thanks, I'll give this a try and let you know.
Re^2: forwarding emails with perl??
by bfdi533 (Friar) on Sep 20, 2006 at 17:11 UTC

    I have been looking at this for some time and need to handle email received from stdin via a pipe and bounce it somewhere else.

    Can I just plug this in somehow into the Email::Folder and Email::Send stream?

      In the case of a single message you would be better off modifying the above to slurp the message off the STDIN into a scalar and pass that to the constructor of Email::Simple, then do much the same as the above

      /J\

        Righto. Here is my stab at this:
        use strict; use warnings; use Email::Send; use Email::Simple; my %received; my @email; #my $box = Email::Folder->new('/home/jonathan/mail/Recruiters/'); @email = <>; my $message = join "\n", @email; my $mail = Email::Simple->new($message); $mail->header_set('To','target@host.com'); my $sender = Email::Send->new({mailer => 'SMTP'}); #my $sender = Email::Send->new({mailer => 'Sendmail'}); $sender->mailer_args([Host => 'localhost']); my $rv = $sender->send ($mail->as_string()); use Data::Dumper; print Dumper($rv); my @available = $sender->all_mailers; print Dumper(@available);

        Unfortunately, though it sppears to be proper code and all, it produces the following error:

        $VAR1 = bless( { 'prop' => {}, 'string' => 'Can\'t call method "address" on an undef +ined value at /usr/lib/perl5/vendor_perl/5.8.8/Email/Send/SMTP.pm lin +e 56, <> line 68. ', 'type' => 'failure', 'errno' => 1 }, 'Return::Value' );

        Anyone have any idea what is wrong here?

Re^2: forwarding emails with perl??
by chrisj0 (Acolyte) on Aug 08, 2005 at 17:54 UTC
    thanks again gellyfish..
    I've written the code similar to the way you show. I added some changes to the header modification to ensure that replies and replies to all work, and that the CC addresses in the message aren't copied on the remailed message.
    This works great and was very easy.

    I've been looking at the module and I don't see a way to only select new messages? I've tried giving Email::Folder->new only the new folder but the module complains that it's not an IMAP directory.
    Is there a way to only process new messages? I'd like to add a command line option to only remail new messages rather than the entire inbox. Would I have to use another module to do this?
    Any suggestions would be great
    TIA,
    chrisj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://480582]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-24 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found