Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: forwarding emails with perl??

by gellyfish (Monsignor)
on Sep 20, 2006 at 18:30 UTC ( [id://573970]=note: print w/replies, xml ) Need Help??


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

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\

Replies are listed 'Best First'.
Re^4: forwarding emails with perl??
by bfdi533 (Friar) on Sep 20, 2006 at 21:02 UTC
    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\

        The my $message = join '', @email; worked perfectly. Thanks.

        Now I have other issues about relay being denied because I am trying to keep the originator email address (from header) in place so as to make it a bounce and I cannot relay for addresses outside of my domain. But, that is a problem that I need to fix locally somehow, I guess.

        Still, if there were a better way to do this without having to open relay up ...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found