26.13. Using procmail
前一頁 | 章 26. 電子郵件 | 下一頁

## 26.13. Using procmail

Contributed by Marc Silver.

The procmail utility is an incredibly powerful application used to filter incoming mail. It allows users to define “rules” which can be matched to incoming mails to perform specific functions or to reroute mail to alternative mailboxes and/or email addresses. procmail can be installed using the `mail/procmail` port. Once installed, it can be directly integrated into most MTAs; consult your MTA documentation for more information. Alternatively, procmail can be integrated by adding the following line to a `.forward` in the home directory of the user utilizing procmail features:

"|exec /usr/local/bin/procmail || exit 75"

The following section will display some basic procmail rules, as well as brief descriptions on what they do. These rules, and others must be inserted into a `.procmailrc` file, which must reside in the user's home directory.

The majority of these rules can also be found in the procmailex(5) manual page.

Forward all mail from `<user@example.com>` to an external address of `<goodmail@example2.com>`:

:0 * ^From.*user@example.com ! goodmail@example2.com

Forward all mails shorter than 1000 bytes to an external address of `<goodmail@example2.com>`:

:0 * < 1000 ! goodmail@example2.com

Send all mail sent to `<alternate@example.com>` into a mailbox called `alternate`:

:0 * ^TOalternate@example.com alternate

Send all mail with a subject of “Spam” to `/dev/null`:

:0 ^Subject:.*Spam /dev/null

A useful recipe that parses incoming `FreeBSD.org` mailing lists and places each list in its own mailbox:

:0 * ^Sender:.owner-freebsd-\/[^@]+@FreeBSD.ORG { LISTNAME=${MATCH} :0 * LISTNAME??^\/[^@]+ FreeBSD-${MATCH} }

前一頁 | 上一層 | 下一頁
26.12. Using fetchmail | 起始頁 | 章 27. Network Servers

本文及其他文件，可由此下載： ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。

若有 FreeBSD 方面疑問，請先閱讀 FreeBSD 相關文件，如不能解決的話，再洽詢 <questions@FreeBSD.org>。
關於本文件的問題，請洽詢 <doc@FreeBSD.org>。