Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Email Forwarding

by randomact (Initiate)
on Feb 05, 2013 at 17:30 UTC ( #1017226=perlquestion: print w/replies, xml ) Need Help??
randomact has asked for the wisdom of the Perl Monks concerning the following question:

Am sending an email to an Address on a linux server in the aliases file, it then runs script. Works great, but I need to include the message not the "test" that I send to that email. Basically, I need a script to forward a email message but change the From and Subject.

#!/usr/bin/perl -w print "Content-type: text/html\n\n"; #$title='Perl Mail demo'; $to='newaddress@mydomain.com'; $from= 'newfrom@anotherdomain.com'; $subject='newsubject'; $body='This is a test'; open(MAIL, "|/usr/sbin/sendmail -t"); ## Mail Header print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; ## Mail Body print MAIL "$body\n"; $body = substr($body,0,500); close(MAIL); print "<html><head><title>$title</title></head>\n<body>\n\n"; ## HTML content sent, let use know we sent an email print "<h1>$title</h1><p>A message has been sent from $from to $to</p></body></html>";

Thanks for the Help

Replies are listed 'Best First'.
Re: Email Forwarding
by aitap (Deacon) on Feb 05, 2013 at 18:24 UTC
    Where do you want to get the message from, system mailbox? Try reading /var/mail/$username (and parsing it with help from some MIME-parsing/creating module, like Email::MIME or MIME::Tools).
    Sorry if my advice was wrong.

      The email would come from "replaceme@thedomain.com" w/ Subject: "this is the subject to replace" Which "replaceme" is in the Aliase file as: replaceme: "|/msg/forward.pl" When an email is received, the perl script is ran, but I need it to include the Message that is sent.

        Then use one of the modules specified to read and parse the text going from STDIN. You can read from STDIN filehandle using diamond operator (<>), like this:  my $whole_message = do { local $/; <STDIN> }; (see also $/ for more information on slurping filehandle contents).
        Sorry if my advice was wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1017226]
Front-paged by Arunbear
help
Chatterbox?
[Corion]: ambrus: Yeah, I read that, but it's somewhat vague as in what I really have to implement, and where/how my "other" mainloop should/needs to call AnyEvent
[Corion]: (or maybe I just work better from existing code that I munge until it works and I understand it rather than a short abstract text like "implement everything that's needed" ;) )
[ambrus]: Corion: I think in this case you can get away with only a stub for idle, one that always dies when you create it, because AnyEvent::HTTP doesn't use it, not even indirectly through AnyEvent::Handle or AnyEvent::Socket or AnyEvent::DNS.
[Corion]: The "and I understand it" part is optional.
[Corion]: ambrus: Yes but I also need to implement the file / IO watcher, because Prima has that (in Prima::File), and I need to supply the appropriate thing to make push_write etc. work with Prima
[ambrus]: Corion: yes, you need to implement the io watcher, which should be simple because Prima::File is basically that, and the timer watcher form Prima::Timer
[Corion]: ... or so I think. As I said, I'm somewhat vague on how to make AnyEvent cooperate with a callback-driven IO event loop that gives me callbacks when data is available or can be written
[ambrus]: what push_write thing? I don't think you need that. that's implemented generically by AnyEvent::Handle
[Corion]: ambrus: Yeah, that's what I think as well. But you give me an idea, maybe I should start with implementing the timer, as that should be far simpler and with fewer edge-cases/nasty interaction than the file watcher
[ambrus]: You only provide the watcher part that tells when the handle is readable or writable, not the actual writing and reading.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2016-12-08 12:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (141 votes). Check out past polls.