HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to set rules for mailx?
Operating System - HP-UX
1829102
Members
2594
Online
109986
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2007 03:28 PM
01-18-2007 03:28 PM
Hi!
I am pretty beginner... Is it possible to set rules on mails/mail? similar to outlook (at least simple rules?).
Example I want filter out and save those message automatically if sent by perticular sender.
Thanks,
Sanjay
I am pretty beginner... Is it possible to set rules on mails/mail? similar to outlook (at least simple rules?).
Example I want filter out and save those message automatically if sent by perticular sender.
Thanks,
Sanjay
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2007 05:10 PM
01-18-2007 05:10 PM
Solution
In unix-style email environment, this can be done in a different way.
Instead of doing the filtering in the client (or Mail User Agent), you can make the mail server (Mail Transfer Agent; sendmail in HP-UX) do the filtering. The classic tool for this is called "procmail": it is available from the HP-UX Porting Archive.
http://hpux.cs.utah.edu/hppd/hpux/Networking/Mail/procmail-3.22/
Here's an introduction to the use of procmail:
http://userpages.umbc.edu/~ian/procmail.html
With procmail, you can create rules using regular expressions, matching either mail headers, mail content or both. You can also make procmail feed your email to any program or shell script you wish, and make filtering decisions according to the result code of those programs. You can even make those programs pre-process the content of your emails, if you wish.
Note that there are several ways to install procmail: you can just install the binary and use the $HOME/.forward file to enable the use of procmail on a per-user basis. Or you can make slight modifications to sendmail configuration to make procmail be the "local delivery agent", so all users can use procmail by simply writing the rules they want to their $HOME/.procmailrc. If the $HOME/.procmailrc does not exist for some users, procmail works just like sendmail's standard local delivery agent.
Instead of doing the filtering in the client (or Mail User Agent), you can make the mail server (Mail Transfer Agent; sendmail in HP-UX) do the filtering. The classic tool for this is called "procmail": it is available from the HP-UX Porting Archive.
http://hpux.cs.utah.edu/hppd/hpux/Networking/Mail/procmail-3.22/
Here's an introduction to the use of procmail:
http://userpages.umbc.edu/~ian/procmail.html
With procmail, you can create rules using regular expressions, matching either mail headers, mail content or both. You can also make procmail feed your email to any program or shell script you wish, and make filtering decisions according to the result code of those programs. You can even make those programs pre-process the content of your emails, if you wish.
Note that there are several ways to install procmail: you can just install the binary and use the $HOME/.forward file to enable the use of procmail on a per-user basis. Or you can make slight modifications to sendmail configuration to make procmail be the "local delivery agent", so all users can use procmail by simply writing the rules they want to their $HOME/.procmailrc. If the $HOME/.procmailrc does not exist for some users, procmail works just like sendmail's standard local delivery agent.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2007 02:00 AM
01-19-2007 02:00 AM
Re: How to set rules for mailx?
Thanks Matti!
I wasnt interested in mail server, actually I am able to read mails using mailx/mail/pine (mostly I use mailx). Again newly heard of procmail from you... I do not see .procmailrc Can I create a new file and edit it? I will appreciate if you point out some examples (if time permits). Actually I am interested in saving mail attachments (not all... only for maill sent by perticular user which also have same subject pattern). Is it possible to save attachment to some folder automatically by setting rule?
Thanks in advance.
Sanjay
I wasnt interested in mail server, actually I am able to read mails using mailx/mail/pine (mostly I use mailx). Again newly heard of procmail from you... I do not see .procmailrc Can I create a new file and edit it? I will appreciate if you point out some examples (if time permits). Actually I am interested in saving mail attachments (not all... only for maill sent by perticular user which also have same subject pattern). Is it possible to save attachment to some folder automatically by setting rule?
Thanks in advance.
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2007 06:40 AM
01-20-2007 06:40 AM
Re: How to set rules for mailx?
Pine might have just enough filtering functionality to do what you need, but mail and mailx definitely do not have any filtering rule functionality, so you might need a procmail-based solution.
If you install and use procmail, you must write your own .procmailrc. If none exists, procmail does not change the default email behavior at all.
If you want to automate the handling of attachments, you'll need the "munpack" tool. It's available in the "mpack" package in the Porting Archive:
http://hpux.cs.utah.edu/hppd/hpux/Users/mpack-1.6/
The necessary .procmailrc rule for your case would be something like this:
:0 W: attachment-extractor.lock
* ^From:.*someaddress@somewhere\.example
* ^Subject: subject-pattern
| munpack -C /desired/attachment/directory
The first line sets up a lockfile "attachment-extractor.lock", so that if the mail server happens to handle several matching mails in parallel, their handling is serialized here to prevent filename conflicts. You can choose the name of the lockfile freely: procmail will create the lockfile when starting to process an email that matches this rule, and delete the lockfile when processing is complete. If the lockfile already exists (i.e. another matching email is currently being processed), procmail waits.
The next two lines define the match conditions. These are standard regular expressions: note that a single dot means "any single character can be at this location", so if you want to specify an explicit dot (like in an email address), you should put a backslash before the dot. The combination ".*" means "here can be any number of any characters". See "man 5 regexp" for a full description of regular expression syntax.
The final line tells what must be done if a mail matches all the conditions. In this case, it will be piped to "munpack", which will extract any attachments from it. You'll need to specify the directory where you want to store the attachments (the -C option). By default, munpack will not overwrite any old files: if there is an existing file with the same name as the new attachment, munpack will add ".1", ".2" etc. to the end of the new filename to avoid name conflicts. If you need to overwrite the old attachments, munpack can do that too: see its documentation for details.
If you install and use procmail, you must write your own .procmailrc. If none exists, procmail does not change the default email behavior at all.
If you want to automate the handling of attachments, you'll need the "munpack" tool. It's available in the "mpack" package in the Porting Archive:
http://hpux.cs.utah.edu/hppd/hpux/Users/mpack-1.6/
The necessary .procmailrc rule for your case would be something like this:
:0 W: attachment-extractor.lock
* ^From:.*someaddress@somewhere\.example
* ^Subject: subject-pattern
| munpack -C /desired/attachment/directory
The first line sets up a lockfile "attachment-extractor.lock", so that if the mail server happens to handle several matching mails in parallel, their handling is serialized here to prevent filename conflicts. You can choose the name of the lockfile freely: procmail will create the lockfile when starting to process an email that matches this rule, and delete the lockfile when processing is complete. If the lockfile already exists (i.e. another matching email is currently being processed), procmail waits.
The next two lines define the match conditions. These are standard regular expressions: note that a single dot means "any single character can be at this location", so if you want to specify an explicit dot (like in an email address), you should put a backslash before the dot. The combination ".*" means "here can be any number of any characters". See "man 5 regexp" for a full description of regular expression syntax.
The final line tells what must be done if a mail matches all the conditions. In this case, it will be piped to "munpack", which will extract any attachments from it. You'll need to specify the directory where you want to store the attachments (the -C option). By default, munpack will not overwrite any old files: if there is an existing file with the same name as the new attachment, munpack will add ".1", ".2" etc. to the end of the new filename to avoid name conflicts. If you need to overwrite the old attachments, munpack can do that too: see its documentation for details.
MK
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP