Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Simple forward of email with minor mods

by tel2 (Scribe)
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 = '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

Comment on Simple forward of email with minor mods
Download Code
Re: Simple forward of email with minor mods
by zwon (Monsignor) on Jun 19, 2010 at 07:44 UTC
Re: Simple forward of email with minor mods
by Krambambuli (Deacon) 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 (Scribe) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://845512]
Approved by zwon
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-09-20 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls