簡單瞭解procmail

tonykorn97發表於2008-10-21

一,什麼是procmail

  procmail 是一個強大得驚人的過濾進入郵件的應用程式。 它允許使用者定義 “規則”, 並用這些規則來匹配進入的郵件, 進而執行某些特定的功能, 或將這些郵件轉發到

其他信箱和/或郵件地址。

[@more@]

二,Procmail, A Mail Delivery Agent (郵件分發代理)

Different uses include:
1,sorting incoming email into different folders or files
2, preprocessing email
3, starting an event or program when email is received
4, automatically forwarding email to others

啟用procmail
1,sendmail 預設已經啟用。
2,postfix: 修改 /etc/postfix/main.cf

mailbox_command = /usr/bin/procmail

3, 檢視是否安裝procmail
[root@station10 ~]# rpm -aq | grep procmail
procmail-3.22-17.1
[root@station10 ~]#

三,procmail and Access controls

initial controls
1,SELinux policy restricts mail utilies to certain directories
2,procmail runs as nobody
3,procmail is owned by the mail group
4,/var/spool/mail is writable only by root and the mail group

必須的操作:改變procmail的許可權,配置sgid
chmod g+s $(which procmail)


配置:
postfix修改/etc/postfix/mail.cf檔案:

#mailbox_command = /some/where/procmail
#mailbox_command = /some/where/procmail -a "$EXTENSION"
mailbox_command = /usr/bin/procmail
"/etc/postfix/main.cf" 672L, 26912C written

[root@station10 ~]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
[root@station10 ~]# chmod g+s $(which procmail)
[root@station10 ~]# ls -al $(which procmail)
-rwxr-sr-x 1 root mail 92452 Jul 13 2006 /usr/bin/procmail
[root@station10 ~]#


四,intro to procmail configuration

Configuration files are processed in order if they exist
1,/etc/procmailrc
2,~/.procmailrc 使用者自定義的操作

Elements within a configuration file
1,Directives: VERBOSE=yes
2,Variables: LOGFILE=/var/spool/mail/procmail.log
3,Recipes
Begin with a ":0" line and flags
Zero or more match lines using regular expressions
one or more action lines

五,Sample Procmail Recipe

:0*
^From.*joshua* ---名字中包含這個名字
^Subject:.*ADSL ---主題中包含這些字元的
{
:0 c
! ---轉發給這個人

:0:
ADSL
}

man pages:procmailex,procmailrc,procmail

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/312079/viewspace-1012225/,如需轉載,請註明出處,否則將追究法律責任。

相關文章