安装好postfix后进行配置:
1. 配置DNS
1.1 提供主机名:
[root@www postfix-2.10.8]# hostname mail.a.com
[root@www postfix-2.10.8]# hostname
mail.a.com
[root@www postfix-2.10.8]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=mail.a.com
1.2 安装bind
[root@www postfix-2.10.8]# rpm -qa | grep bind
bind-libs-9.8.2-0.30.rc1.el6_6.3.i686
bind-utils-9.8.2-0.30.rc1.el6_6.3.i686
bind-9.8.2-0.30.rc1.el6_6.3.i686
1.3 修改配置文件named.conf添加监听本地53端口:
listen-on port 53 { 127.0.0.1; 192.168.85.128; };
[root@www ~]# netstat -ntlp | grep :53
tcp 0 0 192.168.85.128:53 0.0.0.0:* LISTEN 11763/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 11763/named
1.4 /etc/named.rfc1912.zones 中添加正/反向区域及其数据文件:
zone "a.com" IN {
type master;
file "a.com.zone";
allow-update { none; };
allow-transfer { none; };
};
zone "85.168.192.in-addr.arpa" IN {
type master;
file "192.168.85.zone";
allow-update { none; };
allow-transfer { none; };
};
[root@www ~]# cat /var/named/a.com.zone
$TTL 600
@ IN SOA ns.a.com. root.a.com. (
2015082501
3600
1800
36000
3600 )
IN NS ns.a.com.
IN MX 10 mail.a.com.
ns IN A 192.168.85.128
mail IN A 192.168.85.128
[root@www ~]# cat /var/named/192.168.85.zone
$TTL 600
@ IN SOA ns.a.com. root.a.com. (
2015082501
3600
1800
36000
3600 )
IN NS ns.a.com.
128 IN PTR ns.a.com.
128 IN PTR mail.a.com.
1.5 更改数据文件权限和属主属组:
[root@www named]# chown root.named a.com.zone 192.168.85.zone
[root@www named]# chmod 640 a.com.zone 192.168.85.zone
1.6 重启服务并测试:
[root@www named]# dig -t A mail.a.com @192.168.85.128
mail.a.com. 600 IN A 192.168.85.128
[root@www named]# dig -x 192.168.85.128 @192.168.85.128
128.85.168.192.in-addr.arpa. 600 IN PTR mail.a.com.
128.85.168.192.in-addr.arpa. 600 IN PTR ns.a.com.
2. 配置postfix
2.1 简单配置:
[root@www postfix-2.10.8]# vim /etc/postfix/main.cf修改以下几项需要的配置
myhostname = mail.a.com
myorigin = a.com
mydomain = a.com
mydestination = $myhostname, localhost, localhost.$modoamin, $mydomain
mynetworks = 192.168.85.0/24, 127.0.0.0/8
inet_interfaces = $myhostname, localhost
2.2 重新加载
[root@www postfix]# service postfix reload
Reloading postfix: [ OK ]
[root@www postfix]# netstat -ntlp | grep :25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 9959/master
[root@www postfix]# tail /var/log/maillog
Aug 25 03:49:03 www postfix/master[9959]: reload -- version 2.10.8, configuration /etc/postfix
2.3 邮件测试:
[root@www postfix]# telnet mail.a.com 25
Trying 192.168.85.128...
Connected to mail.a.com.
Escape character is '^]'.
220 mail.a.com ESMTP Postfix
helo mail.a.com
250 mail.a.com
mail from: lw@abc.com
250 2.1.0 Ok
rcpt to: zyd@xyz.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
hello!!!
.
250 2.0.0 Ok: queued as AA2DA64B8C
quit
221 2.0.0 Bye
Connection closed by foreign host.
查看日志:
Aug 27 03:00:38 www postfix/qmgr[15777]: 6DC7C64BB1: from=<lw@a.com>, size=288, nrcpt=1 (queue active)
Aug 27 03:00:38 www postfix/local[16842]: 6DC7C64BB1: to=<zyd@a.com>, relay=local, delay=33, delays=33/0.07/0/0.02, dsn=2.0.0, status=sent (delivered to mailbox)此时是为其中继的;
下面测试不中继:
修改main.cf中的mynetworks = 127.0.0.0/8要求只为127.0.0.0/8中继不再为192.168.85.0/24内主机中继;
再次测试:
[root@mail ~]# telnet 192.168.85.128 25
Trying 192.168.85.128...
Connected to 192.168.85.128.
Escape character is '^]'.
220 mail.a.com ESMTP Postfix
helo mail.a.com
250 mail.a.com
mail from: root@a.com
250 2.1.0 Ok
rcpt to: lw@abc.com
454 4.7.1 <lw@abc.com>: Relay access denied表示中继被拒绝,不再为192.168.85.0/24的主机中继只为127.0.0.0/8的主机中继;
2.3.1 还可以测试用外部的XP主机上的OutLookExpress(192.168.85.132)向内部主机(192.168.85.128)发邮件
main.cf配置信息:
myhostname = mail.a.com
myorigin = a.com
mydomain = a.com
mydestination = $myhostname, localhost, localhost.$modoamin, $mydomain
mynetworks = 192.168.85.0/24, 127.0.0.0/8
inet_interfaces = $myhostname, localhost
新建三个用户用于测邮件收发:使用其他主机上的用户收发邮件时,这个用户不能是管理员而是一个普通用户,该用户还要有密码;
lw密码lw
lby密码lby
zyd密码zyd
以lw用户为例:
不要勾选‘使用安全密码验证登录’选项
登录后想lby用户发邮件:
如果发不出去邮件,可以打开本地防火墙-->高级-->网络连接设置中的设置选项-->服务中的几项勾选
发送邮件:
查看mail日志是否有邮件传输记录:
[root@www ~]# tail /var/log/maillog
Aug 26 04:13:57 www postfix/qmgr[14618]: B87A861654:
from=<lw@a.com>, size=1394, nrcpt=1 (queue active)
Aug 26 04:13:57 www postfix/smtpd[14623]: disconnect from unknown[192.168.85.132]
Aug 26 04:13:57 www postfix/local[14627]: B87A861654:
to=<lby@a.com>, relay=local, delay=0.2, delays=0.09/0.1/0/0.01, dsn=2.0.0,
status=sent (delivered to mailbox)
切换到lby用户上查看邮件:
[zyd@www ~]$ su - lby
Password:
[lby@www ~]$ mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/lby": 1 message 1 new
>N 1 lw Wed Aug 26 04:13 44/1469 "Test"
& 1
Message 1:
From lw@a.com Wed Aug 26 04:13:57 2015
Return-Path: <lw@a.com>
X-Original-To: lby@a.com
Delivered-To: lby@a.com
From: "lw" <lw@a.com>
To: <lby@a.com>
Subject: Test
Date: Wed, 26 Aug 2015 19:14:22 +0800
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0053_01D0E033.6A7AA1C0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157
Status: R
Content-Type: text/plain;
charset="gb2312"
This is test!
测试能否中继邮件:
查看邮件日志:
[root@www ~]# tail /var/log/maillog
Aug 26 04:39:10 www postfix/qmgr[14618]: 9A7BB64B8C: from=<lw@a.com>, size=1392, nrcpt=1 (queue active)
Aug 26 04:39:14 www postfix/smtp[14728]: 9A7BB64B8C: to=<1099649040@qq.com>, relay=mx3.qq.com[183.232.94.123]:25, delay=4.3, delays=0.13/0.11/2/2.1, dsn=2.0.0, status=sent (250 Ok: queued as )
已经发送了,说明此台主机(IP为192.168.85.132)是可以中继的,而且登录到QQ邮箱也确实收到了;
2.3.2 安装dovecot收邮件
以安装rpm格式的dovecot为例
[root@www ~]# yum install dovecot.i686 -y
简单说明:
pop3监听110/tcp imap4监听143/tcp 二者的邮件下载都是以明文方式工作的,可以跟SSL一起工作加密
dovecot支持四种协议:pop3 pops imap4 imaps
编辑dovecot的配置文件是:/etc/dovecot/dovecot.conf,修改
启用protocols = imap pop3 lmtp #可根据需要修改,这里启用默认配置
启动服务:
[root@www ~]# service dovecot start
Starting Dovecot Imap: [ OK ]
[root@www ~]# netstat -ntlp | grep dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 14990/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 14990/dovecot
测试收邮件:
方法一: 使用OutlookExpress收邮件:
用户lw发邮件,然后切换用户到lby收邮件;
方法二: 使用telnet命令测试:
[root@www ~]# telnet mail.a.com 110
Trying 192.168.85.128...
Connected to mail.a.com.
Escape character is '^]'.
+OK Dovecot ready.
USER lby #用户登录
+OK
PASS lby #PASS输入用户的密码
+OK Logged in.
LIST #LIST列出当前用户的邮件
+OK 2 messages:
1 1458
2 1478
.
RETR 1 #PETR打开第一封邮件
+OK 1458 octets
Return-Path: <lw@a.com>
X-Original-To: lby@a.com
Delivered-To: lby@a.com
Received: from USER20150512RO (unknown [192.168.85.132])
by mail.a.com (Postfix) with SMTP id 21C6764179
for <lby@a.com>; Wed, 26 Aug 2015 05:50:25 -0700 (PDT)
Message-ID: <72679D65B2D444A385FA639CA93AA596@USER20150512RO>
From: "lw" <lw@a.com>
To: <lby@a.com>
Subject: mail from lw
Date: Wed, 26 Aug 2015 20:50:50 +0800
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0069_01D0E040.E40F96A0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157
This is a multi-part message in MIME format.
------=_NextPart_000_0069_01D0E040.E40F96A0
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: base64
dGVzdCE=
------=_NextPart_000_0069_01D0E040.E40F96A0
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: base64
PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIj4NCjxIVE1MPjxIRUFEPg0KPE1FVEEgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PWdi
MjMxMiIgaHR0cC1lcXVpdj1Db250ZW50LVR5cGU+DQo8TUVUQSBuYW1lPUdFTkVSQVRPUiBjb250
ZW50PSJNU0hUTUwgOC4wMC42MDAxLjIzNTYyIj4NCjxTVFlMRT48L1NUWUxFPg0KPC9IRUFEPg0K
PEJPRFkgYmdDb2xvcj0jZmZmZmZmPg0KPERJVj48Rk9OVCBzaXplPTI+dGVzdCE8L0ZPTlQ+PC9E
SVY+PC9CT0RZPjwvSFRNTD4NCg==
------=_NextPart_000_0069_01D0E040.E40F96A0-- base64加密了,可以解密后查看
quit #quit退出
+OK Logging out.
Connection closed by foreign host.
然后以用户zyd的身份再向登录上OutlookExpress的ly用户发邮件:
[root@www ~]# telnet 192.168.85.128 25
Trying 192.168.85.128...
Connected to 192.168.85.128.
Escape character is '^]'.
220 mail.a.com ESMTP Postfix
helo mail.a.com
250 mail.a.com
mail from: zyd@a.com
250 2.1.0 Ok
rcpt to: lw@a.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Subject:Hello,i'm zyd
thank you!
.
250 2.0.0 Ok: queued as 8FCFC64BAE
quit
221 2.0.0 Bye
Connection closed by foreign host
[root@www ~]# tail /var/log/maillog
Aug 26 06:51:10 www postfix/qmgr[14618]: 8FCFC64BAE: from=<zyd@a.com>, size=313, nrcpt=1 (queue active)
Aug 26 06:51:10 www postfix/local[15333]: 8FCFC64BAE: to=<lw@a.com>, relay=local, delay=80, delays=80/0.06/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
登录到OutlookExpress上查收邮件:
点击发送/接受-->接受全部
至此一个能收能发的邮件服务器建成了;
补充:发邮件还不太可能出什么大错,就是收邮件总是爱出错,不是拒绝登录就是不断的验证用户密码超时无法登陆,我也遇到了,不过解决了,上网查了很多资料再结合mail日志才解决的。
上面我遇到的错误的解决方法:
http://blog.chinaunix.net/uid-30212356-id-5174809.html