《NetBSD指南-26.6.高级邮件工具》
发表于 : 2010-03-08 1:59
When you start using mail, you won't probably have very sophisticated requirements and the already described standard configuration will satisfy all your needs. But for many users the number of daily messages will increase with time and a more rational organization of the mail storage will become necessary, for example subdividing mail in different mail boxes organized by topic. If, for example, you subscribe to a mailing list, you will likely receive many messages every day and you will want to keep them separate from the rest of your mail. You will soon find that you are spending too much time every day repeating the same manual operations to organize your mail boxes.
Why repeat the same operations manually when you can have a program perform them automatically for you? There are numerous tools that you can add to your mail system to increase its flexibility and automatically process your messages. Amongst the most known and used there are:
First, procmail must be installed using the package system (mail/procmail) or pkg_add.
Next, the configuration of postfix must be changed, in order to use procmail as local mailer:
The line defines the path of the procmail program (you can see where procmail is installed with the command which procmail).
The last step is the creation of the procmail configuration file, containing the recipes for mail delivery.
Let's say that, for example, you subscribed to a mailing list on roses whose address is “[email protected]” and that every message from the list contains the following line in the header:
Assuming you want to automatically sort all mails going over that list into the local mail folder "roses_list", the procmail configuration file (.procmailrc) looks like this:
The previous file contains only one rule, beginning with the line containing “:0”. The following line identifies all messages containing the string “Delivered-To: [email protected]” and the last line says that the selected messages must go to the roses_list mailbox (which you should have created in $MAILDIR). The remaining messages will be delivered to the default mailbox. Note that $MAILDIR is the same directory that you have configured with mutt:
Of course the mailing list is only an example; procmail is a very versatile tool which can be used to filter mail based on many criteria. As usual, refer to the man pages for more details: procmail(1), procmailrc(5), and procmailex(5) (this last one contains many examples of configuration files).
Why repeat the same operations manually when you can have a program perform them automatically for you? There are numerous tools that you can add to your mail system to increase its flexibility and automatically process your messages. Amongst the most known and used there are:
- procmail, an advanced mail delivery agent and general purpose mail filter for local mail, which automatically processes incoming mail using user defined rulesets. It integrates smoothly with sendmail/postfix.
- spamassassin or spamprobe, to help fight spam.
- metamail, a tool to process attachments.
- formail, a mail formatter.
First, procmail must be installed using the package system (mail/procmail) or pkg_add.
Next, the configuration of postfix must be changed, in order to use procmail as local mailer:
代码: 全选
mailbox_command = /usr/pkg/bin/procmail
The last step is the creation of the procmail configuration file, containing the recipes for mail delivery.
Let's say that, for example, you subscribed to a mailing list on roses whose address is “[email protected]” and that every message from the list contains the following line in the header:
代码: 全选
Delivered-To: [email protected]
代码: 全选
PATH=/bin:/usr/bin:/usr/pkg/bin
MAILDIR=$HOME/Mail
LOGFILE=$MAILDIR/from
:0
* ^Delivered-To: [email protected]
roses_list
代码: 全选
set folder="~/Mail"