最近分配到一台ECS服務器,需要搭建一台郵件服務器。
查了一波資料選擇了Postfix (smtp)和 Dovecot(pop3).
推薦教程:http://www.cnblogs.com/zlbeidou/p/3436332.html (我的是CentOS6.5 如果是Centos7.*的注意selinux,防止出現坑,ubuntu用此教程的話注意使用sudo指令,其他基本相同)
1:配置 DNS 服務器並添加郵件服務器 MX 記錄. 並讓 ISP 支持你的靜態 IP 與域名. (局域網搭建跳過此步驟,服務器必須)
2:安裝 Postfix
[root@server ~]# yum install postfix -y
配置 Postfix
打開 /etc/postfix/main.cf 更改如下配置:
## Line no 75 - Uncomment and set your mail server FQDN ## myhostname = server.cnblogs.com 你的主機名稱(比我是mail.xxx.com,需要加到MX記錄,優先級10) ## Line 83 - Uncomment and Set domain name ## mydomain = cnblogs.com 你的域名(比如我是xxx.com) ## Line 99 - Uncomment ## myorigin = $mydomain ## Line 116 - Set ipv4 ## inet_interfaces = all ## Line 119 - Change to all ## inet_protocols = all ## Line 164 - Comment ## #mydestination = $myhostname, localhost.$mydomain, localhost, ## Line 165 - Uncomment ## mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ## Line 264 - Uncomment and add IP range ## mynetworks = 192.168.1.0/24, 127.0.0.0/8(也可以不改) ## Line 419 - Uncomment ## home_mailbox = Maildir/ (郵件存放目錄)
保存並退出, 重啟 Postfix 服務:
[root@server ~]# /etc/init.d/postfix start [root@server ~]# /etc/init.d/postfix status master (pid 1290) is running... [root@server ~]# chkconfig postfix on
測試 Postfix
通過 telnet 進行測試, 沒有 telnet 可通過 yum 安裝, 一下出現紅色字體表示輸入.
新建測試用戶 fourone:
[root@server ~]# useradd fourone [root@server ~]# passwd fourone
測試功能
[root@server ~]# telnet localhost smtp Trying ::1... Connected to localhost. Escape character is '^]'. 220 server.cnblogs.com ESMTP Postfix ehlo localhost 250-server.cnblogs.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN mail from:<fourone> 250 2.1.0 Ok rcpt to:<fourone> 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> hello fourone . 250 2.0.0 Ok: queued as 3E68E284C quit 221 2.0.0 Bye Connection closed by foreign host.
進入 fourone mail 目錄檢查郵件:
[root@server ~]# ls /home/fourone/Maildir/new/ 1369816264.Vfd00I41ec0M251771.server.cnblogs.com [root@server ~]# cat /home/fourone/Maildir/new/1369816264.Vfd00I41ec0M251771.server.cnblogs.com Return-Path: <fourone@cnblogs.com> X-Original-To: fourone Delivered-To: fourone@cnblogs.com Received: from localhost (localhost [IPv6:::1]) by server.cnblogs.com (Postfix) with ESMTP id 3E68E284C for <zl>; Wed, 29 May 2013 14:00:36 +0530 (IST) Message-Id: <20130529083047.3E68E284C@server.cnblogs.com> Date: Wed, 29 May 2013 14:00:36 +0530 (IST) From: fourone@cnblogs.com To: undisclosed-recipients:;
hello fourone
3:安裝 Dovecot
Dovecote 是一款開源 IMAP/POP3 郵件服務器 for Unix/Linux systems.
[root@server ~]# yum install dovecot
配置 Dovecot
打開 /etc/dovecot/dovecot.conf 更改如下配置:
## Line 20 - umcomment ## protocols = imap pop3 lmtp
打開 /etc/dovecot/conf.d/10-mail.conf:
## Line 24 - uncomment ## mail_location = maildir:~/Maildir (遇上面postfix一致)
打開 /etc/dovecot/conf.d/10-auth.conf:
## line 9 - uncomment## disable_plaintext_auth = yes (出現如果不要ssl驗證的則是no) ## Line 99- Add a letter "login" ## auth_mechanisms = plain login
打開 /etc/dovecot/conf.d/10-master.conf:
## Line 83, 84 - Uncomment and add "postfix" #mode = 0600 user = postfix group = postfix
開啟 Dovecot 服務:
[root@server ~]# service dovecot start
Starting Dovecot Imap: [ OK ]
[root@server ~]# chkconfig dovecot on (加入系統啟動項)
測試 Dovecot
[root@server ~]# telnet localhost pop3 Trying ::1... Connected to localhost. Escape character is '^]'. +OK Dovecot ready. user fourone +OK pass 111111 ## Here 111111 is password of user "fourone" ## +OK Logged in. list +OK 1 messages: 1 427 . retr 1 +OK 427 octets Return-Path: <fourone@cnblogs.com> X-Original-To: fourone Delivered-To: fourone@cnblogs.com Received: from localhost (localhost [IPv6:::1]) by server.cnblogs.com (Postfix) with ESMTP id 3E68E284C for <zl>; Wed, 29 May 2013 14:00:36 +0530 (IST) Message-Id: <20130529083047.3E68E284C@server.cnblogs.com> Date: Wed, 29 May 2013 14:00:36 +0530 (IST) From: fourone@cnblogs.com To: undisclosed-recipients:; hello fourone . quit +OK Logging out. Connection closed by foreign host.
Dovecot 測試成功.