標簽:
it |
這里說的 hostname 是指使用 'hostname -f' 命令打印出來的系統(tǒng)主機名,例如:
$ hostname -f mail.example.com
不管您的 Linux 系統(tǒng)是否作為公網(wǎng)服務(wù)器,我們都強烈建議您設(shè)置一個合適的主機名。
在 Ubuntu 系統(tǒng)中,主機名的設(shè)置涉及到兩個文件:
用你熟悉的編輯器編輯 /etc/hostname 文件
$cat /etc/hostname mail
編輯 / /etc/hosts 文件
$cat /etc/hosts 127.0.0.1 mail.example.com mail localhost localhost.localdomain
檢查FQDN Name設(shè)置,
Hostname的修改,必須重新啟動機器才能生效
# hostname -f mail.example.com
使用穩(wěn)定的版本,需要'main' 和 'universe' , 使用安裝系統(tǒng)的時候ubuntu缺省的源,也是沒有問題的。
如果覺得163速度慢,大家可以直接換成sohu,就可以使用。
$ cat /etc/apt/source.list deb http://mirrors.sohu.com/ubuntu hardy main universe deb http://mirrors.sohu.com/ubuntu hardy-updates main universe deb http://mirrors.sohu.com/ubuntu hardy-security main universe deb http://ppa.launchpad.net/iredmail/8.04/ubuntu hardy main
導(dǎo)入 PPA的 gpg key
# apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xd9226c1a29511386b3b9f8bc8dc2c190ddf700d3
$ cat /etc/apt/source.list deb http://mirrors.sohu.com/ubuntu jaunty main universe deb http://mirrors.sohu.com/ubuntu jaunty-updates main universe deb http://mirrors.sohu.com/ubuntu jaunty-security main universe
$ cat /etc/apt/sources.list deb http://mirrors.sohu.com/ubuntu karmic main universe deb http://mirrors.sohu.com/ubuntu karmic-updates main universe deb http://mirrors.sohu.com/ubuntu karmic-security main universe
#sudo apt-get update
# sudo su -
#wget http://iredmail.googlecode.com/files/iRedMail-0.5.1.tar.bz2 #tar jxvf iRedMail-0.5.1.tar.bz2
#cd iRedMail-0.5.1/pkgs/ #bash get_all.sh
# cd .. # bash iRedMail.sh
安裝完成后,一定要仔細閱讀iredmail.tip,里面包括設(shè)置信息和賬號,下面各個應(yīng)用的訪問路徑。這個是本安裝的范例(http://code.google.com/p/iredmail/source/browse/extra/iRedMail.tips )
iRedAdmin 是iredmail官方開發(fā)郵件后臺管理,目前可以管理ldap 版本,mysql的版本正在開發(fā)中。
大家也可以通過iredmail官方提供的demo (http://www.iredmail.org/admin_demo.html )深入了解iredadmin
可以使用https://your_server/iredadmin 訪問iredadmin (注意是 https )
可以使用https://your_server/ldap 訪問iredadmin (注意是 https )
可以使用https://your_server/awstats/awstats.pl 訪問Awstats (注意是 https )
可以使用https://your_server/phpmyadmin 訪問phpMyAdmin (注意是 https )
如果你選擇mysql來存儲虛擬用戶和domain,那么PostfixAdmin來管理用戶和domain,使用https://your_server/postfixadmin 訪問phpMyAdmin (注意是 https )
DNS記錄,需要你到你的域名托管商那里進行設(shè)置或者你自己管理DNS服務(wù)器。不少域名托管商不支持txt記錄或者不支持DKIM記錄,所以你就無法使用SPF和DKIM的功能。
DNS的修改,需要48小時以上才能生效。
國內(nèi)的萬網(wǎng)是不支持DKIM,目前新網(wǎng)是支持SPF和DKIM
郵件的MX記錄最好是指向機器A記錄,盡量不要直接指向IP地址(不符合規(guī)范)。
mail.example.com 192.168.1.100
example.com mail.example.com
example.com. 3600 IN TXT "v=spf1 mx mx:mail.example.com -all"
example.com. 3600 IN TXT "v=spf1 ip4:192.168.1.100 -all"
可以通過iredmail.tips 獲得域名的DKIM,也可以在命令行下輸入
# amavisd-new showkeys ; key#1, domain example.com, /var/lib/dkim/example.com.pem dkim._domainkey.example.com. 3600 TXT ( "v=DKIM1; p=" "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDGNVMuQRKq YeySIzqTGTm3xRzF" "/ZzhmMnpZkEcVVjFAk+t7E388oFGu/knyh6KBKwpZxHUN5HoOYVjMu dqaR2FcSvK" "z+joFj8Vh3rXoTLa1zHDyfD7hI CzxdEgmQZ8MJM5rjPPrRGZXn PowNYDsd6nDJ86" "N38iFYU+jALBYDLBwQIDAQAB")
把上面記錄添加到ISP的DNS記錄
dkim._domainkey.example.com. v=DKIM1; p=MIGfMA0....(省略)DLBwQIDAQAB
添加完DNS記錄后,如果記錄生效,可以通過運行命令檢測
# amavisd-new testkeys TESTING: dkim._domainkey.example.com => pass
下面有幾種方法,可以幫助你檢測DNS是否設(shè)置生效和正常工作
C:\>nslookup Default Server: unknown Address: 192.168.1.1 > server 4.2.2.1 Default Server: vnsc-pri.sys.gtei.net Address: 4.2.2.1 > set type=mx > example.com Server: vnsc-pri.sys.gtei.net Address: 4.2.2.1 Non-authoritative answer: example.com MX preference = 20, mail exchanger = mail.example.com > set type=txt > example.com Server: vnsc-pri.sys.gtei.net Address: 4.2.2.1 Non-authoritative answer: example.com text = "v=spf1 ip4:192.168.1.100 -all" > dkim._domainkey.example.com Server: vnsc-pri.sys.gtei.net Address: 4.2.2.1 Non-authoritative answer: dkim._domainkey.example.com text = "v=DKIM1; p= MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsgZaIvYHA os2jbp3CHW0 AwrTnAEwV1p4EaZP/JuF8t1BETBVg6WJr3YWN5ijC pi9vnw96nmf/u5MgtbLwZ+AzDBkbOY7Jbb/hIO+ mpmmfdJAY3w8KoXLCuQKDysX Oys45YtfJEj66s51EHH3W+iXPYw3I/NWHjY3a5/mXnk4XJQIDAQAB"
如果你的機器沒有dig命令,你需要安裝
apt-get install dnsutils
這個時候,就可以使用dig命令
# host exmple.com example.com has address 192.168.1.100 example.com mail is handled by 10 mail.example.com.
# dig txt hotmail.com ; <<>> DiG 9.4.2-P2 <<>> txt hotmail.com ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43130 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;hotmail.com. IN TXT ;; ANSWER SECTION: hotmail.com. 3600 IN TXT "v=spf1 include:spf-a.hotmail.com include:spf-b.hotmail.com include:spf-c.hotmail.com include:spf-d.hotmail.com ~all" ;; Query time: 176 msec ;; SERVER: 64.71.161.8#53(64.71.161.8) ;; WHEN: Sat Dec 5 08:43:51 2009 ;; MSG SIZE rcvd: 157
#dig txt dkim._domainkey.example.comweb工具
通過這個不但可以檢查各種DNS設(shè)置,還可以檢測到你的IP地址,是否已經(jīng)給列入黑名單。
http://zmailer.org/mxverify.html
http://www.brandonchecketts.com/emailtest.php
網(wǎng)頁里有一個郵箱地址,你可以通過安裝過程中創(chuàng)建的第一個用戶www,發(fā)送郵件給這個測試郵箱,你就可以馬上看到結(jié)果
查看發(fā)送過去的郵件的源碼, 如果顯示 dkim=pass 和 SPF: pass 就表示正常
Received-SPF: pass (google.com: domain of www@example.com designates 66.160.197.199 as permitted sender) client-ip=66.160.197.199; Authentication-Results: mx.google.com; spf=pass (google.com: domain of www@example.com designates 66.160.197.199 as permitted sender) smtp.mail=www@example.com; dkim=pass header.i=@example.com
Linux下,如果出現(xiàn)問題,那么排錯最佳的方式就是查看log,不過為了性能,有些應(yīng)用,缺省下沒有開啟錯誤log,我們需要啟用。
# tail /var/log/apache2/error.log #查看log # tail -0f /var/log/apache2/error.log #實時查看log
當你采用ldap來驗證用戶,當用戶登錄出現(xiàn)問題的時候,你就需要查看ldap的log,看那個地方出錯。
loglevel 256 # <-- change form 0 to 256
/etc/init.d/slapd restart
tail /var/log/openldap.log
當接收郵件有問題的時候,我們需要查看dovecot的log,
mail_debug = yes #把注釋去掉
# /etc/init.d/dovecot restart
# tail /var/log/dovecot.log
當RoundCube里過濾器不工作或者有問題的情況下,你就需要查看sieve的log
# tail /var/log/sieve.log
查看郵件發(fā)送的問題,就需要查看posfix Log
#tail /var/log/mail.log
Postfix 排錯,還可以通過Postfix提供郵件隊例隊列管理工具:
postqueue -p 列出隊列里的所有郵件 postsuper -d ID 刪除一封郵件 postsuper -d ALL 刪除所有郵件 postsuper –h ID 保留郵件 postsuper -r ALL 重新排例 postcat -q ID 顯示郵件內(nèi)容 postqueue -f 清空郵件
iRedmail提供pop,imap和pops,imaps的連接,可以根據(jù)需要選擇采用哪種方式
Protocol | Unencrypted port | TLS Port | SSL Port |
SMTP | 25 | 587 | 465 |
POP3 | 110 | 110 | 995 |
IMAP | 143 | 143 | 993 |
這個faq會不定期更新,最新的FAQ,大家可以直接訪問 http://www.iredmail.org/faq.html
郵件系統(tǒng)的備份,可以考慮采用rsync, unison,如果數(shù)據(jù)量大,可以參考文章 http://blog.daviesliu.net/2008/04/24/sync/
灰名單,是有效阻止垃圾郵件的手段,原理是當一個新的郵箱地址發(fā)郵件過來,都會先拒絕2次,然后第三次才會接收下來。一般發(fā)垃圾郵件的人,因為隊列太長,就不會再嘗試投遞。
灰名單會導(dǎo)致第一次發(fā)送延遲,不過第二次以后就沒有問題。如果希望停止灰名單
編輯/etc/postfix-policyd.conf
# 1=on 0=off GREYLISTING=0 #把1改成0
重新啟動policy服務(wù)
# /etc/init.d/postfix-policyd restart
iRedmail的安裝過程,我們設(shè)置了root的alias,如果我們希望修改郵箱地址。
編輯/etc/postfix/aliases 改成你需要的郵箱地址。以后系統(tǒng)的警告郵件就會發(fā)送到新的郵箱。
# See man 5 aliases for format postmaster: root clamav: root root: www@18demo.com policyd: www@18demo.com amavis: root
修改后,需要運行下面命令才可以生效。
# postalias /etc/postfix/aliases
這個時候可以測試一下,給root發(fā)一封郵件,是否生效
cd iRedMail-0.5.1 mail -s "test" root < iRedMail.tips
iRedmail 是通過Amavisd-new + alterMIME 實現(xiàn)出站的郵件都添加免責聲明。alterMIME支持Per-domain,Sub-domain,Per-user添加免責聲明,同時支持txt和 html格式。缺省情況下,iRedMail沒有啟用。
# ------------ Disclaimer Setting --------------- # Uncomment this line to enable singing disclaimer in outgoing mails. $defang_maps_by_ccat{+CC_CATCHALL} = [ 'disclaimer' ]; #把注釋去掉
#echo 'Testing disclaimer.' > /etc/postfix/disclaimer/default.txt
# /etc/init.d/amavis restart
這個時候,所有往外發(fā)送的郵件,都會在底部加上 'Testing disclaimer.'
當你希望卸載或者重新安裝iredmail,那么可以利用iRedMail提供的工具,快速卸載iredmail各個組件,進行重新安裝
# cd iRedMail-0.5.1/tools/ # bash clear_iredmail.sh
按照提示進行就可以,當你重新安裝的時候,你還是需要運行下載腳本,再運行安裝腳本。
iRedMail提供腳本,可以讓用戶快速添加用戶
你可以編輯create_mail_user_MySQL.sh,修改默認值,如果你安裝的時候修改的郵件的存儲路徑,那么你必須修改腳本的 STORAGE_BASE_DIRECTORY
創(chuàng)建郵箱用戶的缺省密碼是和用戶名相同
# cd iRedMail-0.5.1/tools/ # bash create_mail_user_MySQL.sh exmple.com user1 user2 user3
這個時候,會創(chuàng)建output.sql 文件
# mysql -uroot -p mysql> USE vmail; mysql> SOURCE /path/to/output.sql;
使用create_mail_user_OpenLDAP.sh腳本,可以快速創(chuàng)建ldap的郵件用戶,我們需要修改腳本
創(chuàng)建郵箱用戶的缺省密碼是和用戶名相同
STORAGE_BASE_DIRECTORY="/var/vmail/vmail01" #如果你安裝的時候修改的郵件的存儲路徑 LDAP_SUFFIX="dc=iredmail,dc=org" #你的ldap SUFFIX BINDPW='passwd' #ldap管理員cn=manager 密碼
運行腳本,創(chuàng)建用戶
# bash create_mail_user_OpenLDAP.sh example.com user1 user2
要注意的是:下面的設(shè)置,是可以讓你的服務(wù)器是可以發(fā)送大附件,也需要對方的服務(wù)器能夠接收大附件,否則還是無法發(fā)送出去。
如果你是希望郵件客戶端發(fā)送大附件,那么你只需要運行
# postconf -e message_size_limit='104857600' #把附件增加到100m
重啟postfix服務(wù)
# /etc/init.d/postfix restart
如果希望webmail,發(fā)送大附件,那么你還需要多修改2個地方
1:編輯/etc/php5/apache2/php.ini 文件
upload_max_filesize = 100M; post_max_size = 100M;
2:修改/usr/share/apache2/roundcube/.htaccess 文件
php_value upload_max_filesize 100M php_value post_max_size 100M
重啟apache服務(wù)
# /etc/init.d/apache2 restart
編輯/etc/postfix/main.cf 文件,在smtpd_recipient_restrictions 下添加下面內(nèi)容
smtpd_recipient_restrictions = reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unlisted_recipient, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname, check_policy_service inet:127.0.0.1:10031 ##添加下面內(nèi)容 reject_rhsbl_sender dsn.rfc-ignorant.org, reject_rbl_client dnsbl.njabl.org, reject_rbl_client dnsbl.ahbl.org, reject_rbl_client bl.spamcop.net, reject_rbl_client zen.spamhaus.org,
重啟postfix服務(wù)
# /etc/init.d/postfix reload
如果希望停用殺毒和發(fā)垃圾的功能,編輯/etc/postfix/main.cf 文件,到把最底下的這行注釋掉
content_filter = smtp-amavis:[127.0.0.1]:10024
這個時候,postfix接收到的郵件,就不會再交給amavis處理,就可以把amavisd, clamd, freshclam服務(wù)停止。不過要注意的是這個時候DKIM的功能,也是無法使用,因為iredmail的DKIM是通過amavis來實現(xiàn)的。
rolaod postifx服務(wù)
#update-rc.d amavis purge #update-rc.d clamav purge # /etc/init.d/postfix reload
目前iRedMail還沒有集成fetchmail的功能,如果你需要使用fetchmail,你可以自己集成
apt-get install fetchmail
START_DAEMON=yes #把no改為yes
set daemon 300 #5分鐘取一次郵件 set syslog set postmaster root set no bouncemail defaults: timeout 300 antispam -1 batchlimit 100 #用戶:shakechen 也可以是 shakechen@126.com 密碼是:12345678 本地的郵箱:www@18demo.com poll pop3.126.com protocol POP3 user shakechen there with password 12345678 is www@18demo.com here
最后一行意思是把126郵箱里的用戶的郵件,投遞到本地的郵箱賬號 www@18demo.com
chmod 600 /etc/fetchmailrc chown fetchmail /etc/fetchmailrc
/etc/init.d/fetchmail start
# tail /var/log/syslog Dec 7 16:01:36 mail fetchmail[4179]: 723 messages (723 seen) for shakechen at pop3.126.com (36923210 octets). Dec 7 16:01:37 mail fetchmail[4179]: sleeping at Mon Dec 7 16:01:37 2009 for 30 seconds Dec 7 16:02:07 mail fetchmail[4179]: awakened at Mon Dec 7 16:02:07 2009 Dec 7 16:02:08 mail fetchmail[4179]: 723 messages (723 seen) for shakechen at pop3.126.com (36923210 octets). Dec 7 16:02:09 mail fetchmail[4179]: sleeping at Mon Dec 7 16:02:09 2009 for 30 seconds
如果你修改了計算機名字或者希望使用自己的信息創(chuàng)建自己的ssl key。
# wget http://iredmail.googlecode.com/hg/iRedMail/tools/generate_ssl_keys.sh
# SSL key. export SSL_CERT_FILE="${ROOTDIR}/certs/iRedMail_CA.pem" export SSL_KEY_FILE="${ROOTDIR}/private/iRedMail.key" export TLS_COUNTRY='CN' export TLS_STATE='GuangDong' export TLS_CITY='ShenZhen' export TLS_COMPANY="${HOSTNAME}" export TLS_DEPARTMENT='IT' export TLS_HOSTNAME="${HOSTNAME}" export TLS_ADMIN="root@${HOSTNAME}"
# bash generate_ssl_keys.sh SSL keys were generated: - /root/certs/iRedMail_CA.pem - /root/private/iRedMail.key
/etc/ssl/private/iRedMail.key /etc/ssl/certs/iRedMail_CA.pem
如果用戶是使用郵件客戶端,是無法收取到j(luò)unk的郵件,所以iredmail缺省是讓spam的郵件進入收件箱。如果我們希望讓spam的郵件,不進入收件箱,直接存在垃圾郵箱的文件夾里。
# cd /var/vmail/sieve # cp dovecot.sieve.sample dovecot.sieve
# /etc/init.d/dovecot restart
如果我們裝完iremdail后,希望修改hostname(FQDN),那么我們需要修改下面相關(guān)的內(nèi)容。
裝好系統(tǒng)后,如何評估系統(tǒng)的發(fā)垃圾和病毒能力?總不能自己給自己發(fā)垃圾郵件和病毒郵件吧。
http://www.gfi.com/emailsecuritytest/
我們可以通過GFI來測試我們郵件系統(tǒng)的發(fā)垃圾和病毒能力。
當你的郵箱驗證通過后,他會發(fā)送垃圾郵件和病毒郵件到你的郵箱,你就可以檢測到郵件系統(tǒng)的反垃圾和病毒查殺能力。
http://www.antispam-ufrj.pads.ufrj.br/
測試郵件服務(wù)器是否被設(shè)成公開轉(zhuǎn)發(fā)站
http://www.abuse.net/relay.html
postqueue -p
postsuper -d MessageID
mailq | tail +2 | awk ‘BEGIN { RS = “” } # $7=sender, $8=recipient1, $9=recipient2 { if ($7 == “info@otherdomain.com” && $9 == “”) print $1 } ‘ | tr -d ‘*!’ | postsuper -d -
mailq | tail +2 | awk ‘BEGIN { RS = “” } # $7=sender, $8=recipient1, $9=recipient2 { if ($8 == “you@yourdomain.com” && $9 == “”) print $1 } ‘ | tr -d ‘*!’ | postsuper -d -
mailq | grep senderhostname | awk ‘{ print $1′} | postsuper -d -
postsuper -h ALL
當處理完后,再把隊列移回來
postsuper -r ALL
測試郵件,可以用客戶端, 也可以使用命令行測試,這樣更加直接.
我們需要把我們的登錄賬號和密碼一起編碼
user:www@example.com
pass: iredmail
# perl -MMIME::Base64 -e 'print encode_base64("www\@example.com\0www\@example.com\0iredmail")'; d3d3QGV4YW1wbGUuY29tAHd3d0BleGFtcGxlLmNvbQBpcmVk bWFpbA==
# telnet localhost 25 #在服務(wù)器上telnet到本地,下面的是正常輸出 Trying::1... Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 u910.example.com ESMTP iRedMail (Ubuntu) ehlo example.com #握手 250-u910.example.com 250-PIPELINING 250-SIZE 15728640 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN auth plain d3d3QGV4YW1wbGUuY29tAHd3 d0BleGFtcGxlLmNvbQBpcmVk bWFpbA== # 輸入base 64后的用戶名和密碼 235 2.7.0 Authentication successful mail from:<www@example.com> #使用 www@example.com 賬號對外發(fā)送郵件 250 2.1.0 Ok rcpt to:<shake.chen@gmail.com> #發(fā)送郵件到 shake.chen@gmail.com 這個郵箱 250 2.1.5 Ok data #輸入data命令后,下面就是郵件的內(nèi)容 354 End data with <CR><LF>.<CR><LF> to:shake.chen@gmail.com #這是郵件里顯示的發(fā)送給誰。 from:www@example.com #那個賬號發(fā)送過來的 subject: test by telnet smtp #郵件的主題 test , just a test ,check the subject whetehr working. . #寫完郵件后,輸入一個點,回車,就表示郵件完成。 250 2.0.0 Ok: queued as B6B4820EC9 quit #退出 221 2.0.0 Bye Connection closed by foreign host.
可以在遠程使用命令行或者本地來測試pop3
# telnet localhost 110 #登錄110端口 Trying::1... Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready. user www@example.com #輸入登錄的郵件賬號 +OK pass iredmail #賬號的密碼,這里直接輸入密碼就可以 +OK Logged in. list #查看郵箱里的郵件 +OK 4 messages: 1 1182 2 6195 3 1588 4 878 . retr 1 #顯示第一封郵件內(nèi)容 quit #退出 +OK Logging out. Connection closed by foreign host.