Operating System - HP-UX
1834102 Members
2810 Online
110063 Solutions
New Discussion

using .forward file to process mail

 
SOLVED
Go to solution
Tim Nelson
Honored Contributor

using .forward file to process mail

I would like to use the command function of the .forward file to process some information that is send via email. Basically I want to automatically save the attachment that is sent and drop the header info. i.e. System "A" gathers some system info and emails the info as an attachment to joe on System "B". I have an entry in joe's .forward file to execute a script. The script would then cut the mail header info and save the attachment automatically.
Does someone have something already created that would cut off the header info and then uudecode the attachment and save it?
Any ideas would be appreciated.
Thanks !
5 REPLIES 5
Bill Thorsteinson
Honored Contributor
Solution

Re: using .forward file to process mail

Look at procmail, which is designed to allow you to do stuff like this. Send the mail though uudecode. This should do exactly what you want. The configuration file is '.procmailrc'.

I don't have it installed on my HP server as we do this kind of processing on our Linux box.
Sridhar Bhaskarla
Honored Contributor

Re: using .forward file to process mail

Tim,

You can use procmail to easily do this job for you. You can get it from the HP-UX porting center.

http://hpux.cs.utah.edu/hppd/hpux/Networking/Mail/procmail-3.21/

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Bill Hassell
Honored Contributor

Re: using .forward file to process mail

.forward follows the same rules as /etc/mail/aliases so putting a processing script into .forward is easy but since you can create special mail addresses without a username in /etc/mail/aliases, most people will use the aliases file. Here's the steps:

vi /etc/mail/aliases

(add an entry for the new mail address--note: the address is not subject to the 8 character username limit in /etc/passwd)

mynewmailaddess: "| /full/path/to/Script"

If your script needs some options or perhaps additional filters:

mynewmailaddess: "| /usr/bin/tee -a /var/tmp/mymail.log | /full/path/to/Script /my/special/file"

and so on...

Now, most important: these commands *AND* the files and directories they need to access *MUST* be owned by daemon, not root. That's because rmail is normally used to deliver the mail (the Mlocal directive in sendmail.cf) and run as the daemon user.

Once aliases is finished, run the command:

newaliases

(which is identical to sendmail -bi)
and now you can test your setup by sending an email to: mynewmailaddress@mymachine.com

Now, as far as the script goes, the header will always start with From as the first word on the first line. Then header lines (widely varied number and order), followed by one blank line which then defines the beginning of the body of the message.

At this point you will see the beauty of a plain ASCII message (easy to parse, easy to read) and/or the infamous MIME attachments and the wide variety of message types, languages, file types, encoding techniques, etc. To see a plain ASCII message come through:

mailx -sTestMessage mynewmailaddress@mymachine.com < /etc/issue

To see the other side of email, send the message from a PC-based messaging system...

NOTE: There is no way to control who will send email to this address so your script must include validity processing. And unlike cron or shell scripts run at the command line, error messages will have to logged someplace...my preference is to use logger and send the errors to syslog.log (not the errant message, just a note about the sender).


Bill Hassell, sysadmin
Tim Nelson
Honored Contributor

Re: using .forward file to process mail

Thanks to all.. The procmail is interesting but too much for this simple project..
Tim Nelson
Honored Contributor

Re: using .forward file to process mail

Thanks to all who responded