Creating a mail forwarding script

Hello. I need some help creating a script which will grab my e-mail headers and forward it to another e-mail address(to my cell phone).
I know my unix server has procmail to process mail stuff but I don't really have the time (or the know-how) to figure it out. If someone could write the script for me, I would be grateful (and will award points). If you need any information about the unix server, just ask..... Thanks.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

joolsSenior Systems AdministratorCommented:
Most unix servers allow you to create a .forward file in your home directory.

The .forward file should just contain the email address of the person you need the mail to go to.


Give it a go, can't hurt!

J :)
ajmaAuthor Commented:
I want it to only forward the headers.
I need it to parse the e-mail because my cell phone will only take 160 characters.
Also, I need it to save a copy on the server too.
Most cell phone email systems will only
forward first 160 characters including senders name
subject and first few characters of the message.

Even if you forward the full email, your cell phone
email system will truncate the message for you.

I just use .forward to forward the message.


\localusername, phonenumner@cellphone-address
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

ajmaAuthor Commented:
well, if the message is over 160, it truncates it to 5 messages. I don't want 5 messages coming in when I get an e-mail.

All I want is to know how to make the e-mail go thru a script so I can parse it to only send the subject and the from fields. (and possibly block spam...)
ok.. in that case.. someone has to write a procmai
script... Lemme see if I can get you one,
procmail (and its associated formail utility) can slice and dice Email in just about any way imaginable, although the syntax is concise to the point of being cryptic.

You can forward just the headers of incoming Email using the procmail 'h' flag, so a very simple .procmalirc file would be:

:0 Whc: phone.lock
   # don't forward daemon/error messages or mailing lists
   # weed out duplicates
| formail -D 8192 phone.cache
  : 0 ehc # if it is new, send  headers to the phone

The 'c' flag would cause a copy (of the entire message) to be generated and be processed by the rest of the procmail script for local storage.  From there you could get fancier and use formail to just pick out the "interesting headers" or do some processing with sed to pull out the first line or two of the message body.

How you get the message into procmail depends on your system configuration.  Some systems use procmail for their default delivery mechanisms, others will require you to set up a .forward file that pipes your mail into procmail, something like:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ajmaAuthor Commented:
Thanks. Works well!

One last question:
what is the phone.cache thing?

phone.cache is just a database of message IDs.  The 'formail -D 8192 phone.cache' line causes it to remember recent last message IDs (up to a cache size 8192).  It returns "success" if a duplicate is found.  (The next stanza uses 'e', so it will happen only if the previous result was false... meaning no duplicate was found.)

If you aren't worried about duplicates, you could take out that bit:
:0 hc
 # don't forward daemon/error messages or mailing lists
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.