CentOS5.5下PostFix邮件系统配置,采用比较简单的yum来进行安装,当然也可以用源码进行编译安装。
邮件postfix发送安装配置
[root@dyq ~]# yum -y install postfix #输入安装postfix
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: centos.ustc.edu.cn
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
addons | 951 B 00:00
base | 2.1 kB 00:00
extras | 2.1 kB 00:00
updates | 951 B 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package postfix.i386 2:2.3.3-2.1.el5_2 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
====================================================
Package Arch Version Repository Size
====================================================
Installing:
postfix i386 2:2.3.3-2.1.el5_2 base 3.6 M
Transaction Summary
====================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 3.6 M
Downloading Packages:
postfix-2.3.3-2.1.el5_2.i386.rpm | 3.6 MB 00:27
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : postfix 1/1
Installed:
postfix.i386 2:2.3.3-2.1.el5_2
Complete!
[root@dyq ~]# vim /etc/postfix/main.cf
myhostname = mail.kiccleaf.com
mydomain = kiccleaf.com
myorigin=$mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
relay_domains = $mydestination
mynetworks = 192.168.1.0/28, 127.0.0.0/8,60.191.49.228/24 #填写自己的公网ip
home_mailbox = Maildir/
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version) ← 找到这一行,接此行添加如下行:
smtpd_banner = $myhostname ESMTP unknow ← 添加这一行,不显示SMTP服务器的相关信息
|
在配置文件的文尾,添加如下行:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
smtpd_sasl_auth_enable = yes ← 服务器使用SMTP认证
smtpd_sasl_local_domain = $myhostname ← 指定SMTP认证的本地域名(主机名)
smtpd_sasl_security_options = noanonymous ← 不允许匿名的方式认证
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
message_size_limit = 15728640
[root@dyq ~]# vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd ← 找到此行,将“saslauthd”改为“auxprop”
↓
pwcheck_method: auxprop ← 不使用系统用户密码作为用户的SMTP认证密码
[root@dyq ~]# vi /etc/sysconfig/saslauthd
MECH=shadow ← 找到这一行,在前面加#
↓
#MECH=shadow ← 不使用shadow机制
FLAGS= ← 找到此行,在等号后面添加“sasldb”
↓
FLAGS=sasldb ← 定义认证方式为sasldb2
[root@dyq ~]# mkdir /etc/skel/Maildir
[root@dyq ~]# chmod 700 /etc/skel/Maildir
[root@dyq ~]# ll /home/
total 8
drwx------ 2 mysql mysql 4096 Mar 18 00:51 mysql
drwx------ 2 www www 4096 Mar 18 01:52 www
[root@dyq ~]# adduser leaf #添加一个用户leaf
[root@dyq ~]# ll /home/ #查看用户是否创建
total 12
drwx------ 3 leaf leaf 4096 Mar 21 11:02 leaf
drwx------ 2 mysql mysql 4096 Mar 18 00:51 mysql
drwx------ 2 www www 4096 Mar 18 01:52 www
[root@dyq ~]# passwd leaf #配置leaf用户的密码
Changing password for user leaf.
New UNIX password: #输入leaf用户密码
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password: #再次输入leaf用户密码
passwd: all authentication tokens updated successfully.
[root@dyq ~]# mkdir /home/leaf/Maildir (默认情况下已经创建)
mkdir: cannot create directory `/home/leaf/Maildir': File exists
[root@dyq ~]# chmod 700 /home/leaf/Maildir
[root@dyq ~]# chown leaf. /home/leaf/Maildir
[root@dyq ~]# saslpasswd2 -u mail.kiccleaf.com -c leaf
Password: #输入leaf用户密码
Again (for verification):#再次输入leaf用户密码
[root@dyq ~]# chgrp postfix /etc/sasldb2
[root@dyq ~]# chmod 640 /etc/sasldb2
[root@dyq ~]# alternatives --config mta
There are 2 programs which provide 'mta'.
Selection Command
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number: 2 #选择2
[root@dyq ~]# chkconfig saslauthd on #添加到服务,以后可以直接用service saslauthd [start/stop/restart]进行操作
[root@dyq ~]# chkconfig --list saslauthd #查看是否为系统自动启动 2~5 为on
saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@dyq ~]# /etc/rc.d/init.d/saslauthd start #启动服务
Starting saslauthd: [ OK ]
[root@dyq ~]# chkconfig postfix on #添加到服务,以后可以直接用service postfix [start/stop/restart]进行操作
[root@dyq ~]# chkconfig --list postfix #查看是否为系统自动启动 2~5 为on
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@dyq ~]# /etc/rc.d/init.d/postfix start #启动服务
Starting postfix: [ OK ]
|
POP / IMAP 服务器的构建( Dovecot )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
[root@dyq ~]# yum -y install dovecot
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: centos.ustc.edu.cn
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
addons | 951 B 00:00
base | 2.1 kB 00:00
extras | 2.1 kB 00:00
updates | 951 B 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package dovecot.i386 0:1.0.7-7.el5 set to be updated
--> Processing Dependency: libmysqlclient.so.15 for package: dovecot
--> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: dovecot
--> Processing Dependency: libpq.so.4 for package: dovecot
--> Running transaction check
---> Package mysql.i386 0:5.0.77-4.el5_5.4 set to be updated
--> Processing Dependency: perl(DBI) for package: mysql
---> Package postgresql-libs.i386 0:8.1.22-1.el5_5.1 set to be updated
--> Running transaction check
---> Package perl-DBI.i386 0:1.52-2.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
===================================================
Package Arch Version Repository Size
===================================================
Installing:
dovecot i386 1.0.7-7.el5 base 1.6 M
Installing for dependencies:
mysql i386 5.0.77-4.el5_5.4 updates 4.8 M
perl-DBI i386 1.52-2.el5 base 600 k
postgresql-libs i386 8.1.22-1.el5_5.1 updates 196 k
Transaction Summary
==================================================
Install 4 Package(s)
Upgrade 0 Package(s)
Total download size: 7.2 M
Downloading Packages:
(1/4): postgresql-libs-8.1.22-1.el5_5.1.i386.rpm | 196 kB 00:01
(2/4): perl-DBI-1.52-2.el5.i386.rpm | 600 kB 00:03
(3/4): dovecot-1.0.7-7.el5.i386.rpm | 1.6 MB 00:09
(4/4): mysql-5.0.77-4.el5_5.4.i386.rpm | 4.8 MB 00:34
-------------------------------------------------------------------------------------------
Total 151 kB/s | 7.2 MB 00:48
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : perl-DBI 1/4
Installing : mysql 2/4
warning: /etc/my.cnf created as /etc/my.cnf.rpmnew
Installing : postgresql-libs 3/4
Installing : dovecot 4/4
Installed:
dovecot.i386 0:1.0.7-7.el5
Dependency Installed:
mysql.i386 0:5.0.77-4.el5_5.4 perl-DBI.i386 0:1.52-2.el5
postgresql-libs.i386 0:8.1.22-1.el5_5.1
Complete!
[root@dyq ~]# vi /etc/dovecot.conf
protocols = imap pop3
default_mail_env = maildir:~/Maildir
|
#如果开启防火墙Iptables 请添加以下端口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@dyq ~]# iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp--dport 25 -j ACCEPT
[root@dyq ~]# iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
[root@dyq ~]# iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT
[root@dyq ~]# /etc/rc.d/init.d/iptables save #保存刚添加的记录
Saving firewall rules to /etc/sysconfig/iptables: [ OK ]
[root@dyq ~]# /etc/init.d/iptables restart #重启防火墙
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]
[root@dyq ~]# chkconfig dovecot on #添加到服务,以后可以直接用service dovecot [start/stop/restart]进行操作
[root@dyq ~]# chkconfig --list dovecot #查看是否为系统自动启动 2~5 为on
dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@dyq ~]# /etc/rc.d/init.d/dovecot start #启动服务
Starting Dovecot Imap: [ OK ]
|
测试php邮件发送
[root@dyq www]# vim mail.php
1
2
3
4
5
6
7
8
9
10
|
<?php
$to
=
'kiccleaf@163.com'
;
$subject
=
'the subject test'
;
$message
=
'hello!测试用例!'
;
$headers
=
'From: leaf@kiccleaf.com'
.
"\r\n"
.
'Reply-To: leaf@kiccleaf.com'
.
"\r\n"
.
'X-Mailer: PHP/'
. phpversion();
mail(
$to
,
$subject
,
$message
,
$headers
);
?>
|
打开浏览器http://youip/mail.php 再查看邮件是否已经收到邮件
也可以用foxmail客户端进行测试.