fetchmail 是一款收信程式,支援 POP2、POP3、APOP、IMAP 以及 ETRN 協定的伺服器。它與 Pine、popclient 這類工具最大的差別在於:拿到信之後不直接放進本地信箱,而是把郵件交給本地郵件系統重新投遞一次,因此能與既有的 MTA 與收信規則無縫銜接。
fetchmail 更新速度快,文中以 RedHat 5.1 附帶的 4.6.5-1 為例,新舊版本的設定檔格式略有差異;最新版可自 sunsite.unc.edu 及其鏡像站取得。
直接從命令列執行:
fetchmail -p POP3 -u isee dns.nuaa.edu.cn
其中 isee 是帳戶,dns.nuaa.edu.cn 是郵件伺服器,使用 POP3 協定。只想檢查有沒有新信而不真的取回,加上 -c:
fetchmail -p POP3 -u isee -c dns.nuaa.edu.cn
-?, --help 顯示說明 -V, --version 顯示版本 -c, --check 只檢查信箱 -s, --silent 安靜執行,不輸出訊息 -v, --verbose 詳細輸出運行資訊,供除錯 -d, --daemon 以守護行程方式執行 -L, --logfile 指定日誌檔 --syslog 使用系統日誌 -f, --fetchmailrc 指定設定檔 -I, --interface 指定網路介面 -p, --protocol 指定收信協定 -P, --port 指定連接埠 -a, --all 下載所有郵件,含舊信 -K, --nokeep 下載後刪除伺服器上的信 -k, --keep 下載後保留伺服器上的信 -F, --flush 刪除伺服器上的舊信 -l, --limit 不下載超過指定大小的郵件 -B, --fetchlimit 指定一次最多下載多少封 -r, --folder 指定遠端資料夾
預設設定檔是 ~/.fetchmailrc,關鍵字多與命令列參數一一對應,而命令列參數的優先級高於設定檔。以 # 起首的行是註解,而 there、here、and、with、has、wants、options 這些字純粹是為了可讀性,實際上可以省略。
一個實際例子:
set syslog set postmaster "isee" poll 202.119.64.127 with proto POP3 and options envelope Delivered-To user "mere" there with passWord "xxxxxxx" is isee@snail.home here no keep user "isee" there with password "yyyyyyy" is isee@snail.home here no keep
它的意思是:使用系統日誌;postmaster 設為 isee(投遞出錯時回信的信頭位址);向 202.119.64.127 收信,協定 POP3,並在信件上加上 Delivered-To 標記;帳戶 mere 的口令為 xxxxxxx,收到的信轉交給 isee@snail.home;帳戶 isee 的口令為 yyyyyyy,同樣轉給 isee@snail.home;兩個帳戶都不在伺服器保留副本。
常用關鍵字對照:
set logfile 指定日誌檔 set syslog 使用系統日誌 via 以 DNS 主機名取代 poll 中的位址 proto (-p) 指定協定 port (-P) 指定連接埠 timeout (-t) 指定逾時秒數 interface (-I) 指定網路介面 user (-U) 指定遠端帳戶 is 對應本地與遠端帳戶 to 同 is pass 口令 folder (-r) 指定資料夾 preconnect 連線前執行的外部命令 postconnect 連線後執行的外部命令 keep (-k) / no keep (-K) / flush (-F) / fetchall (-a)
以上只是入門。fetchmail 還有子資料夾支援、對 qmail 虛擬主機後綴的處理等進階功能,想深入可閱讀 man fetchmail 與隨附文件。