CentOS5.5下postfix郵件系統安裝配置

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      = '[email protected]';
$subject = 'the subject test';
$message = 'hello!測試用例!';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To:  [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
  
mail($to, $subject, $message, $headers);
?>

打開瀏覽器http://youip/mail.php   再查看郵件是否已經收到郵件

也可以用foxmail客戶端進行測試.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章