Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Triggering a script via email...continued

by jerrygarciuh (Curate)
on Apr 19, 2002 at 19:49 UTC ( [id://160652]=perlquestion: print w/replies, xml ) Need Help??

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

I have received some suggestions in the CB regarding this and wanted to see if any other possibilities exist.

I have a script which I wish to run everytime mail arrives for specificaddress@mysite.com . I am not allowed to set up a pipe in etc/mail/aliases on this server (no _root for the wicked). And it is not possible to do so in the SMTP's .redirect file in our local folders. Obviously procmail is one way to do this but I have been told it can be a real nuisance to learn.

What I would like to know is given these limitations, what is my simplest course of action?
TIA
jg
_____________________________________________________
Think a race on a horse on a ball with a fish! TG

Replies are listed 'Best First'.
Re: Triggering a script via email...continued
by andreychek (Parson) on Apr 19, 2002 at 20:07 UTC
    You're right, procmail by itself can be a bit of a pain to learn. However, perhaps you could take a bit of procmail, and use it to pipe a given message into a Perl script. Then you'd be at home :-)

    At work, we're using something like the following in a particular users .procmailrc file in their home directory:
    :0 b * ^From:.*@somedomain.com * ^Subject:.*Re: Your message | /usr/local/bin/NeatoPerlScript.pl
    This takes any message originating from the domain "@somedomain.com", containing the subject "Re: Your message". and pipes the body of the email message into the script "NeatoPerlScript.pl". Then, within your Perl script, just check your standard input for the contents of the email.

    Now, you did say something about doing it every time a message arrived. In that case, just drop the "From" and "Subject" clauses, and it'll affect every message coming in to that particular user.

    Hope that helps!
    -Eric
      While debugging this, I recommend using   :0 ic: at the top of the procmail rule. This will ignore errors in the pipe, and continues processing other rules. This lets you both pass the email message through your filter, and still end up with a copy in your mailbox.

Re: Triggering a script via email...continued
by Juerd (Abbot) on Apr 19, 2002 at 20:00 UTC

    Obviously procmail is one way to do this but I have been told it can be a real nuisance to learn.

    Can't agree. It takes about half an hour to see and understand the recipe syntax for a simple pipe filter, which is worth the trouble.

    :0: * ^TO_specificaddress@mysite.com | perl /home/foo/somescript.pl
    </code>

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

Re: Triggering a script via email...continued
by Dragonfly (Priest) on Apr 19, 2002 at 21:47 UTC
    You might want to be careful with this approach; perhaps you could consider validating the emails you received against a list of known "authorized" IP addresses. The danger is that since email is of course sent in plain text, the message could conceivably be sniffed anywhere en route from the sender to the server, including
    • the sender's network,
    • the router on the sender's network
    • the ISP or any machines the message travels through on the public internet
    • the router on the receiving end
    • the receiving subnet.

    Now I'm probably just being paranoid, but one would think that if soemone with malicious intentions sniffed that particular piece of mail, they might realize what it was, and mount a very effective denial of service attack by mailbombing the address. That is, unless you use some form of IP header validation. Also, make sure you keep the email address private. You wouldn't want a random piece of spam to suddenly trigger something important and/or dangerous. ;-)

    If you get this working, post some code. It's a cool idea and one that has occurred to me before (although I haven't yet tried it out.)

      I cannot agree more fully with DragonFly's comments above - While not a complete solution, one of the earlier nodes that I posted on this site implemented IP-restricted mail delivery for just this type of scenario.

      This node can be found here.

       

        rob_au,
        Thanks for giving me the link again! I was stumped as to who had showed me that node or what the title had been, so I couldn't relocate. Teach me to bookmark, eh?
        Thank you,
        jg
        _____________________________________________________
        Think a race on a horse on a ball with a fish! TG
Re: Triggering a script via email...continued
by sfink (Deacon) on Apr 19, 2002 at 20:28 UTC
    Can you use a .forward file? You should be able to set up a pipe there.
      This is very good news! I set up a .forward just forwarding all mail and it works. I have googled around and have not yet found syntax for pipe in a .forward. Can you help me with that?
      TIA
      jg
      _____________________________________________________
      Think a race on a horse on a ball with a fish! TG
        have not yet found syntax for pipe in a .forward. Can you help me with that?

        When ever I leave the office for a long time, I install a .forward file that both keeps a copy in my mail spool file and also pipes it through an autoreply "I'm not here" process.

        To do that, the .forward file looks like this:

        \graff, "|/usr/bin/vacation graff"
        I'm not sure what will happen if the process crashes. I do know that if the mode on .forward isn't rw-r--r--, my mail server will bounce all mail sent to graff, 'cuz any other mode is either unworkable or a nasty security no-no. I'm not sure, but I might expect it to look up the pipeline process too, to make sure it's not an open door.

        (Presumably, if I only want the mail to go to the process, I just leave off the first part of the line.)

        As you can probably infer from graff's post, the trick is to quote the pipe command. Here's an old .forward of mine:"| /usr/lib/nmh/slocal -user sfink" But the exact syntax is really up to the MTA. This should work with sendmail.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (None)
    As of 2024-04-19 00:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found