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 | [reply] [d/l] |
|
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.
| [reply] [d/l] |
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.
| [reply] [d/l] |
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.) | [reply] |
|
| [reply] |
|
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
| [reply] [d/l] |
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.
| [reply] |
|
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
| [reply] [d/l] |
|
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.)
| [reply] [d/l] |
|
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.
| [reply] [d/l] |