配置全過程如下:
1. 為了讓系統儘量使用最新的安裝包,推薦在進行安裝各軟體前先apt-get update;apt-get upgrade一下。否則還有可能引起軟體安裝的相容性問題,我遇到過幾次在安裝任何軟體時均提示在安裝過程中需先解除安裝e2fsprogs而安裝失敗的情形,最好只好強行刪除該軟體再進行下一步,由於該操作會同時刪除系統中其它重要軟體,應儘量避免。
2. 解除安裝Debian自帶的exim4及相關軟體包。
3. 安裝postfix及相關軟體: apt-get install postfix postfix-doc libsasl2 sasl2-bin courier-imap courier-pop courier-authdaemon
4. 開啟saslauthd服務: 預設地saslauthd是不開啟的,在執行/etc/init.d/saslauthd start後沒有任何反應,需要修改/etc/default/saslauthd檔案如下: START=yes MECHANISMS="shadow" 然後重新輸入命令/etc/init.d/saslauthd start可以看到saslauthd服務開啟的提示。
5. 測試saslauthd服務: 執行ps ax|grep saslauthd,結果中如包含/usr/sbin/saslauthd -a shadow行則說明saslauthd服務正在執行,否則需要檢查配置並啟動saslauthd服務。 sasl2-bin自帶了一個測試saslauthd服務的命令testsaslauthd,如果系統中有使用者test,密碼為testpass,則執行testsaslauthd -u test -p testpass,如迴應: 0: OK "Success." 則說明saslauthd服務工作正常。
6. 配置smtp auth: 修改/etc/postfix/main.cf檔案如下: smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no append_dot_mydomain = no myhostname = vd.vlinux.net alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = $myorigin, localhost.localdomain, localhost relayhost = mynetworks = 127.0.0.0/8 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all home_mailbox = Maildir/ smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_sasl_authenticated, reject_unknown_recipient_domain, reject_non_fqdn_recipient reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, permit 配置中的home_mailbox = Maildir/是指定postfix在進行郵件投遞時使用與Qmail類似的Maildir方式,此方式每封郵件是一個獨立的檔案,比較易於管理,另外IMAP預設也是在使用者目錄的Maildir中訪問郵箱的,所以我選擇了此種方式。在選Maildir方式時,mailbox_command選項應該置空。 其中vd.vlinux.net是本機的主機名,有兩點比較重要: 1)/etc/hosts檔案必須有下面一行: 192.168.5.2 vd.vlinux.net vd 2)/etc/mailname檔案的內容必須是該域的域名。 建立/etc/postfix/sasl/smtpd.conf檔案如下: pwcheck_method: saslauthd saslauthd_path: /var/run/saslauthd/mux mech_list: PLAIN LOGIN 很多資料都講該檔案應該在/usr/lib/sasl2目錄下,我是經過許多次失敗才忽然發現應該放在這裡的,可能是Debian的不同吧。現在重啟postfix:/etc/init.d/postfix restart,透過telnet 25埠檢查smtp auth是否已經開始工作。 vd:~# telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain. Escape character is '^]'. 220 vd.vlinux.net ESMTP Postfix (Debian/GNU) ehlo localhost 250-vd.vlinux.net 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-AUTH LOGIN PLAIN 250 8BITMIME ] 出現250-AUTH ……一行就說明smtp auth功能已經新增。
7. 看起來一切都工作正常了,試一下發信: vd:~# telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain. Escape character is '^]'. 220 vd.vlinux.net ESMTP Postfix (Debian/GNU) ehlo localhost 250-v
配置全過程如下:
1. 為了讓系統儘量使用最新的安裝包,推薦在進行安裝各軟體前先apt-get update;apt-get upgrade一下。否則還有可能引起軟體安裝的相容性問題,我遇到過幾次在安裝任何軟體時均提示在安裝過程中需先解除安裝e2fsprogs而安裝失敗的情形,最好只好強行刪除該軟體再進行下一步,由於該操作會同時刪除系統中其它重要軟體,應儘量避免。
2. 解除安裝Debian自帶的exim4及相關軟體包。
3. 安裝postfix及相關軟體: apt-get install postfix postfix-doc libsasl2 sasl2-bin courier-imap courier-pop courier-authdaemon
4. 開啟saslauthd服務: 預設地saslauthd是不開啟的,在執行/etc/init.d/saslauthd start後沒有任何反應,需要修改/etc/default/saslauthd檔案如下: START=yes MECHANISMS="shadow" 然後重新輸入命令/etc/init.d/saslauthd start可以看到saslauthd服務開啟的提示。
5. 測試saslauthd服務: 執行ps ax|grep saslauthd,結果中如包含/usr/sbin/saslauthd -a shadow行則說明saslauthd服務正在執行,否則需要檢查配置並啟動saslauthd服務。 sasl2-bin自帶了一個測試saslauthd服務的命令testsaslauthd,如果系統中有使用者test,密碼為testpass,則執行testsaslauthd -u test -p testpass,如迴應: 0: OK "Success." 則說明saslauthd服務工作正常。
6. 配置smtp auth: 修改/etc/postfix/main.cf檔案如下: smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no append_dot_mydomain = no myhostname = vd.vlinux.net alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = $myorigin, localhost.localdomain, localhost relayhost = mynetworks = 127.0.0.0/8 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all home_mailbox = Maildir/ smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_sasl_authenticated, reject_unknown_recipient_domain, reject_non_fqdn_recipient reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, permit 配置中的home_mailbox = Maildir/是指定postfix在進行郵件投遞時使用與Qmail類似的Maildir方式,此方式每封郵件是一個獨立的檔案,比較易於管理,另外IMAP預設也是在使用者目錄的Maildir中訪問郵箱的,所以我選擇了此種方式。在選Maildir方式時,mailbox_command選項應該置空。 其中vd.vlinux.net是本機的主機名,有兩點比較重要: 1)/etc/hosts檔案必須有下面一行: 192.168.5.2 vd.vlinux.net vd 2)/etc/mailname檔案的內容必須是該域的域名。 建立/etc/postfix/sasl/smtpd.conf檔案如下: pwcheck_method: saslauthd saslauthd_path: /var/run/saslauthd/mux mech_list: PLAIN LOGIN 很多資料都講該檔案應該在/usr/lib/sasl2目錄下,我是經過許多次失敗才忽然發現應該放在這裡的,可能是Debian的不同吧。現在重啟postfix:/etc/init.d/postfix restart,透過telnet 25埠檢查smtp auth是否已經開始工作。 vd:~# telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain. Escape character is '^]'. 220 vd.vlinux.net ESMTP Postfix (Debian/GNU) ehlo localhost 250-vd.vlinux.net 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-AUTH LOGIN PLAIN 250 8BITMIME ] 出現250-AUTH ……一行就說明smtp auth功能已經新增。
7. 看起來一切都工作正常了,試一下發信: vd:~# telnet localhost 25 Trying 127.0.0.1... Connected to localhost.localdomain. Escape character is '^]'. 220 vd.vlinux.net ESMTP Postfix (Debian/GNU) ehlo localhost 250-v