平臺centos6.5 x86_64最小化安裝php
一,系統設置html
1,echo 'yourserverIP localhost' > /etc/hostslinux
2,sed -i 's/HOSTNAME=*/HOSTNAME=hostname.yourdomain.com/g' /etc/sysconfig/networknginx
3,添加你域名的A記錄(hostname.yourdomain.com A 默認 12.12.12.12)和MX記錄(@ MX 默認 hostname.yourdomain.com),命令host -t mx yourdomain.com確認MX記錄生效web
4,修改時區 cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimecentos
clock -w #同步BIOS時間服務器
二,安裝postfix網絡
yum update -ydom
rpm -q postfix dovecot sendmail dovecot和sendmail默認沒有安裝socket
yum install -y dovecot
vi /etc/postfix/main.cf
myhostname = mail.yourdomain.com 指email服務器的域名
mydomain = yourdomain.com 指系統的主機名稱
myorigin = $mydomain 指定本地發送郵件中來源和傳遞顯示的域名
inet_interfaces = all 設置網絡接口以便Postfix能接收到郵件
mynetworks = 127.0.0.0/8 指定受信任SMTP的列表
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relay_domains = $mydestination 系統傳遞郵件的目的域名列表
home_mailbox = Maildir/ 設置郵箱路徑與用戶目錄
添加如下設置啓用sasl
smtpd_sasl_type = dovecot 啓用dovecot-sasl認證
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes 啓用sasl受權
smtpd_sasl_local_domain = $myhostname sasl的本地域
smtpd_sasl_security_options = noanonymous 不容許匿名登陸
broken_sasl_auth_clients = yes 客戶端兼容支持
smtpd_recipient_restrictions =permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
message_size_limit = 102400000
mailbox_size_limit = 204800000
chkconfig postfix on
service postfix restart
查看具體有效配置項參數
postconf -n
測試一
yum install -y mailx
mail -s 'hello' 12345667@qq.com < /etc/hosts
測試二
yum install -y telnet
telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 mail.yourdomain.com ESMTP Postfix
輸入ehlo yourserverIP
退出quit
三,配置dovecot
1,vi /etc/dovecot/dovecot.conf 支持pop3和imap協議
protocols = imap pop3 lmtp
listen = *
2,vi /etc/dovecot/conf.d/10-auth.conf 指明建立的Unix socket使用的權限,以及用戶和組屬性
disable_plaintext_auth = no 容許密碼明文認證
auth_mechanisms = plain login
3,vi /etc/dovecot/conf.d/10-mail.conf 設置郵箱文件存放位置
mail_location = maildir:~/Maildir
4,vi /etc/dovecot/conf.d/10-master.conf 設置dovecot-sasl認證
# commented on these line:
#unix_listener auth-userdb {
#mode = 0600
#user =
#group =
#}
# change or setup on these line:
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
5,vi /etc/dovecot/conf.d/10-ssl.conf 關閉ssl加密(這裏爲了便於測試)
修改成ssl = no
6,vi /etc/dovecot/conf.d/20-pop3.conf
# uncomment on these line:
pop3_uidl_format = %08Xu%08Xv
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
chkconfig dovecot on
service dovecot start
查看具體有效配置項參數
dovecot -n
telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready. 服務已ok
quit 退出
+OK Logging out
Connection closed by foreign host.
四,建立帳戶
Postfix默認用系統用戶做爲郵件帳號,須要添加Linux系統用戶帳號相互收發郵件測試
groupadd mailusers
adduser -g mailusers -s /sbin/nologin test
passwd test
mkdir -p /home/test/Maildir
chown test:mailusers /home/test/Maildir
chmod -R 700 /home/test/Maildir
下載Foxmail測試該帳號收發郵件
http://www.linuxde.net/2013/07/14774.html
也能夠安裝webmail(就是squirrelmail 界面較老 基本能用)
wget https://nchc.dl.sourceforge.net/project/squirrelmail/stable/1.4.22/squirrelmail-webmail-1.4.22.tar.gz
tar zxvf squirrelmail-webmail-1.4.22.tar.gz
mv squirrelmail-webmail-1.4.22 webmail
cd webmail/
config/conf.pl (./configure)
選1. Organization Preferences -->6. Default Language : en_US 改爲zh_CN
2. Server Settings -->1. Domain : mydomain.com 改爲本身的域名 -->A. Update IMAP Settings : localhost:143 (cyrus)改爲(courier)
4. General Options -->1.Data Directory : 改成/var/www/html/webmail/data/ -->2.Attachment Directory :改成/var/www/html/webmail/attach/
10.language preferences -->1.Default Language :改成zh_CN -->2.Default Charset :改成UTF-8
最好s保存q退出
下載中文語言包:
https://nchc.dl.sourceforge.net/project/squirrelmail/locales/1.4.18-20090526/all_locales-1.4.18-20090526.tar.gz
將其解壓到WebMail
修改郵件存放目錄權限
chown -R nginx:nginx /var/www/html/webmail/data/
在nginx配置文件中server{}段添加以下兩段
location /webmail {
root /var/www/html/;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
}
location ~ /webmail/.*\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/$uri;
include fastcgi_params;
}
service nginx restart
而後http://SERVERIP/webmail就能用創建的系統帳號收發郵件了。