in reply to Re: forwarding emails with perl??
in thread forwarding emails with perl??

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?

Replies are listed 'Best First'.
Re^3: forwarding emails with perl??
by gellyfish (Monsignor) on Sep 20, 2006 at 18:30 UTC

    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?

        I can't be bothered to test at the moment but I think your problem is the

        @email = <>; my $message = join "\n", @email;
        where you could possibly better off doing something like
        my $message = do { local $/; <> };
        But the join you have is unnecessary as you haven't removed the line endings. A
        my $message = join '', @email;
        would be sufficient in your code.

        /J\