Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Simple forward of email with minor mods

by tel2 (Monk)
on Jun 19, 2010 at 06:52 UTC ( #845512=perlquestion: print w/replies, xml ) Need Help??
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 = ''; ??? # 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

Replies are listed 'Best First'.
Re: Simple forward of email with minor mods
by zwon (Abbot) on Jun 19, 2010 at 07:44 UTC
Re: Simple forward of email with minor mods
by Krambambuli (Curate) on Jun 19, 2010 at 12:32 UTC
    Have a look on Mail::Internet and/or Mail::Box. Basicallly, you'll first decompose/split the big all-encompassing string you have into an array of lines. Then you can easily fiddle with the header lines you wish to mangle and send it out afterwards.
Re: Simple forward of email with minor mods
by tel2 (Monk) on Jul 03, 2010 at 00:15 UTC
    Weeks later... Thank you zwon and Krambambuli for your suggestions. I'll get back to you if have any more questions on this subject.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://845512]
Approved by zwon
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-01-19 04:31 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (215 votes). Check out past polls.