script to read mail

Hi,

I want to write a script that will read mail ( for eg: from abc.def@yahoomail.com ). And if it finds a particular subject then do something..

Is it possible....

Please help...
Thanks in adv..

Look into procmail. It's a big subject, be prepared to read quite a bit, but it's certainly possible to do what you want with it.

Its quite possible, PM me if interested in a PERL solution

seen procmail. but i cannot install procmail to the sysatem....
can anyone give me some code to accomplish this..

Thanks

Which Operating System?
Which shell?
Which mail program?

operating system: unix HP
shell: ksh

Dont know anything bout mail program....

Thanks,

---------- Post updated at 08:06 AM ---------- Previous update was at 12:58 AM ----------

Can anyone help me out in writing shell script to read mail.

Thanks..

Add an alias in /etc/mail/aliases like the following
user: user, |/usr/user/myprocess

Run "newaliases"
Send an email to user . The entire email including headers will be used as standard input to the "myprocess" script.
The my process script should look something like:

while read line
do
if [ "a`echo $line|cut -c 1-8`" = "aSubject:" ]
#we add the "a" to the beginning of the test to ensure that the argument is not null
then
test=`echo $line|cut -d":" f2`
if [ "a$test" = "aGOODEMAIL" ]
then
run_my_script
fi
fi
done

No clear (to me) where this mail is stored. Where is the mailbox?
It is on a Yahoo server or on your HP-UX server?

It's my understanding that Yahoo! stores mail on their own servers, where you are very unlikely to get a shell account. You might be able to poll the remote mailbox with the imap protocol. Or you may want to download it all to your machine where it's easier to run a script like jgt suggested because you have total control.

Checkout Fetchmail.

I don't know if it's available for HP-UX, but you can compile it and install it as a regular user on most unix-like OSes. In which case, you use cron to call it instead of installing it as a daemon.

It wakes up every [configurable number of] minutes and fetches all your mail from whatever remote mailboxes you configure it for and it delivers it to the local system just as if they had been delivered there by the mail system.