http://www.perlmonks.org?node_id=845512

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

Dear Monks,

I've done a search here re forwarding emails, but none of the 4 threads I looked at helped me sufficiently.

I'm a customer of a webhost which uses cPanel, so I can set up an email address which pipes received emails to a program. I'd like to write a perl program to read the email (that works), make some slight changes (I'll handle that later), and forward it to another address (that's where I'm stuck).

So, here's my code so far:

{ local($/) = undef; # Prepare for slurp $mail = <>; # Slurp entire email from stdin } # Modify the email subject, etc # Leave this part to me # Forward the email $recipient = 'me@mydomain.com'; ??? # Not sure how to send $mail as an email

Complex, ain't it?

I've sent email before with MIME::Lite, but that's where I have the body in a separate variable. In this case however, I have the entire email (headers and all) in my variable.

I need to be able to forward any attachments which are in the email.

Also, if possible, I'd like to retain the original sender as the "from" address, but this is not a vital.

What can y'all recommend, to get this working?

Thanks. Terry