版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/qq_31813491/article/details/62049977
郵件的收發
1.收發郵件的前期準備
此次試驗需要
虛擬機1:域名設置爲mailwestos.westos.com IP=172.25.254.25
虛擬機2:域名設置爲maillinux.linux.com IP=172.25.254.26
1.1 dns的設置:
虛擬機1設置:
1 hostnamectl set-hostname mailwestos.westos.com ##設置主機名
4 yum install bind -y ##安裝dns服務
5 vim /etc/named.conf
.....
// listen-on port 53 { 127.0.0.1; }; ##加//默認功能全開
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
dnssec-validation no; ##關閉外網連接
.....
8 cd /var/named/
10 vim /etc/named.rfc1912.zones
....
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
};
zone "linux.com" IN {
type master;
file "linux.com.zone";
allow-update { none; };
....
12 cp -p named.localhost westos.com.zone
13 vim westos.com.zone
$TTL 1D
@ IN SOA dns.westos.com. root.westos.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.com.
dns A 172.25.254.25
westos.com. MX 1 172.25.254.25.
14 cp -p westos.com.zone linux.com.zone
15 vim linux.com.zone
$TTL 1D
@ IN SOA dns.linux.com. root.linux.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.linux.com.
dns A 172.25.254.25
linux.com. MX 1 172.25.254.26.
16 systemctl restart named
17 vim /etc/resolv.conf
nameserver 172.25.254.25
18 dig -t mx westos.com ##該命令用於檢測
19 dig -t mx linux.com
21 systemctl stop firewalld.service
虛擬機2設置:
systemctl stop firewalld
vim /etc/resolve.conf
nameserver 172.25.254.25
1.2 25端口的設置
虛擬機1,2都的設置:(只有設置了25端口才能,接收郵件)
rpm -qa | grep postfix ##查詢是否安裝該軟件
[root@jetslinux postfix]# rpm -qa | grep postfix(該命令由後期補充所以主機名與筆記不一致)
postfix-2.10.1-6.el7.x86_64 ##存在該軟件
[root@jetslinux postfix]#
vim /etc/postfix/main.cf
76 myhostname = mailwestos.westos.com ##主機名
83 mydomain = westos.com ##域名
99 myorigin = $mydomain
113 inet_interfaces = all ##此功能爲接收從遠程主機發送的本地郵件(默認只能接收本地用戶)
114 #inet_interfaces = $myhostname
115 #inet_interfaces = $myhostname, localhost
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost
1.3 郵件羣發或別名發送
虛擬機2設置:
56 vim /etc/aliases
.....
admin: root ##別名發送
more: :include:/etc/postfix/users ##羣發
.....
57 postalias /etc/aliases ##編輯完上面文件,必須對其進行加密
58 cd /etc/postfix/
60 vim users
61 mail more ##羣發
63 mail -u student ##查看用戶student郵箱
虛擬機2設置:
68 vim /etc/postfix/virtual
[email protected] (假域名) [email protected](真域名)
@qq.com @linux.com
69 postmap /etc/postfix/virtual ##加密
70 postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual" ##加密
71 ls
virtual.db
72 mail [email protected]
77 systemctl restart postfix.service
78 mail [email protected]
79 mail -u student ##查看郵箱student
使用虛擬機1:
mail [email protected] ##模擬給qq發郵件
1.5 出站地址僞裝
虛擬機2中的設置:
32 vim /etc/postfix/generic
[email protected](true) [email protected]
33 postmap /etc/postfix/generic
34 postconf -d | grep generic
35 postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
36 systemctl restart postfix.service
37 mail [email protected] ##模擬給westos回覆郵件,可注意到恢復人是[email protected]
虛擬機1中的設置:(這樣設置可以發送郵件給qq域名)
87 vim /etc/named.rfc1912.zones
.....
zone "qq.com" IN {
type master;
file "qq.com.zone";
allow-update { none; };
};
.....
89 cd /var/named/
92 cp -p linux.com.zone qq.com.zone
93 vim qq.com.zone
$TTL 1D
@ IN SOA dns.qq.com. root.qq.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.qq.com.
dns A 172.25.254.25
qq.com. MX 1 172.25.254.26.
94 systemctl restart named
95 mail [email protected]
【postqueue -f 再次立即發送所有隊列中的郵件】
1.6 遠程收發郵件
遠端客戶端:(真機做測試)
869 yum install telnet -y ##安裝遠程發送郵件
870 systemctl start telnet
871 telnet 172.25.254.26 25
[root@foundation24 Desktop]# telnet 172.25.254.26 25
Trying 172.25.254.26...
Connected to 172.25.254.26.
Escape character is '^]'.
220 maillinux.linux.com ESMTP Postfix
ehlo hello ##聞訊語句,測試是否連通
250-maillinux.linux.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:[email protected] ##發件人
250 2.1.0 Ok
rcpt to:[email protected] ##收件人
250 2.1.5 Ok
data ##輸入
354 End data with <CR><LF>.<CR><LF>
woshi24 ##郵件內容
.
250 2.0.0 Ok: queued as 38DA017E856
quit ##退出
221 2.0.0 Bye
虛擬機2設置:
41 yum install dovecot -y
42 vim /etc/dovecot/dovecot.conf
......
24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0
49 disable_plaintext_auth = no
......
43 vim /etc/dovecot/conf.d/10-mail.conf
.......
mail_location = mbox:~/mail:INBOX=/var/mail/%u
.......
44 mail -u student ##查看student用戶有無郵件可供測試
45 mail [email protected] ##自己給自己發送郵件
46 mail -u student
47 su - student
48 systemctl restart dovecot ##重啓服務
student用戶下:
1 cd /home/student/
2 ls
3 mkdir mail/.imap
4 mkdir -p mail/.imap
5 ls
6 cd mail/
7 ls
8 cd .imap/
9 touch INBOX
真機測試:
872 yum install mutt -y
876 mutt -f pop://[email protected] ##可查看虛擬機2上的student郵箱
[root@foundation66 software]# yum install thunderbird-31.2.0-1.el7.x86_64.rpm -y
新用戶的建立:
2. 創建虛擬郵箱帳號
2.1 安裝數據庫
虛擬機2設置:
56 yum install mariadb-server.x86_64 httpd php php-mysql -y
57 systemctl start mariadb
58 vim /etc/my.cnf
.....
skip-networking=1
.....
59 mysql_secure_installation ##設置數據庫登陸密碼
60 systemctl restart mariadb.service
61 cd /var/www/html/
62 yum install lftp -y ##安裝此命令,是爲了從主機上獲得數據庫插件
65 tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
67 rm -fr phpMyAdmin-3.4.0-all-languages.tar.bz2
69 mv phpMyAdmin-3.4.0-all-languages/ mysqladmin ##將文件重命名,便於識記
71 cd mysqladmin/
72 cp config.sample.inc.php config.inc.php
73 vim config.inc.php ##裏面的上引號內容可以隨便填寫
74 systemctl restart httpd
75 mysql -uroot -p
MariaDB [(none)]> create user postfix@localhost identified by 'postfix'; ##創建用戶
78 cd /etc/postfix/
79 ls
80 vim mysql-user.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = username
where_field = username
81 cp mysql-user.cf mysql-domain.cf
82 vim mysql-domain.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = domain
where_field = domain
83 cp mysql-user.cf mysql-mailbox.cf
84 vim mysql-mailbox.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = maildir
where_field = username
85 postmap -q "[email protected]" mysql:/etc/postfix/mysql-user.cf
86 postmap -q "[email protected]" mysql:/etc/postfix/mysql-mailbox.cf
87 postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
測試上述文件是否起作用:
【
[root@maillinux postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mysql-user.cf
[email protected]
[root@maillinux postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mysql-mailbox.cf
/var/spool/redhat.co
[root@maillinux postfix]# postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
redhat.com
】
2.3 遠程發送
虛擬機2設置:
【
cd /etc/skel/
3 mkdir -p mail/.imap
4 ls
5 cd mail/
6 ls
7 cd .imap/
8 touch INBOX
】 ##這些操作保證新建用戶可以自動建立/home/username/mail
14 vim /etc/postfix/main.cf
刪掉之前建立的最後兩行
15 postconf -e "virtual_mailbox_base = /home/vmail"
16 postconf -e "virtual_gid_maps = static:888"
17 postconf -e "virtual_uid_maps = static:888"
18 postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"
19 postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
20 postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf"
22 mail [email protected]
24 cd redhat.com/admin/new
2.4 遠程接收郵件
虛擬機2設置:
23 yum install dovecot-mysql.x86_64 -y
24 vim /etc/dovecot/dovecot.conf
.....
48 login_trusted_networks = 0.0.0.0/0 ##允許訪問網絡地址
49 disable_plaintext_auth = no ##開啓明文認證
......
25 vim /etc/dovecot/conf.d/10-auth.conf
123 !include auth-sql.conf.ext ##開啓數據庫認證
26 cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
27 cd /etc/dovecot/
29 vim dovecot-sql.conf.ext (該文件內容,關於數據庫信息,以自己建立的數據庫信息爲準)
32 driver = mysql
71 connect = host=localhost dbname=email(自己建立的數據庫名字) user=postfix(上述新建用戶) password=postfix
78 default_pass_scheme = PLAIN ##加密方式
107 password_query = \
108 SELECT username, domain, password \
109 FROM mailuser WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 888 AS uid, 888 AS gid FROM mailuser WHERE username = '%u'
30 vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n
31 systemctl start dovecot
真機測試登陸:
[root@foundation24 Desktop]# telnet 172.25.254.26 110
Trying 172.25.254.26...
Connected to 172.25.254.26.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user [email protected]
+OK
pass 123
+OK Logged in.
而後在雷鳥上登陸創建用戶,查收郵件
1.收發郵件的前期準備
此次試驗需要
虛擬機1:域名設置爲mailwestos.westos.com IP=172.25.254.25
虛擬機2:域名設置爲maillinux.linux.com IP=172.25.254.26
1.1 dns的設置:
虛擬機1設置:
1 hostnamectl set-hostname mailwestos.westos.com ##設置主機名
4 yum install bind -y ##安裝dns服務
5 vim /etc/named.conf
.....
// listen-on port 53 { 127.0.0.1; }; ##加//默認功能全開
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
dnssec-validation no; ##關閉外網連接
.....
8 cd /var/named/
10 vim /etc/named.rfc1912.zones
....
zone "westos.com" IN {
type master;
file "westos.com.zone";
allow-update { none; };
};
zone "linux.com" IN {
type master;
file "linux.com.zone";
allow-update { none; };
....
12 cp -p named.localhost westos.com.zone
13 vim westos.com.zone
$TTL 1D
@ IN SOA dns.westos.com. root.westos.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.westos.com.
dns A 172.25.254.25
westos.com. MX 1 172.25.254.25.
14 cp -p westos.com.zone linux.com.zone
15 vim linux.com.zone
$TTL 1D
@ IN SOA dns.linux.com. root.linux.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.linux.com.
dns A 172.25.254.25
linux.com. MX 1 172.25.254.26.
16 systemctl restart named
17 vim /etc/resolv.conf
nameserver 172.25.254.25
18 dig -t mx westos.com ##該命令用於檢測
19 dig -t mx linux.com
21 systemctl stop firewalld.service
虛擬機2設置:
systemctl stop firewalld
vim /etc/resolve.conf
nameserver 172.25.254.25
1.2 25端口的設置
虛擬機1,2都的設置:(只有設置了25端口才能,接收郵件)
rpm -qa | grep postfix ##查詢是否安裝該軟件
[root@jetslinux postfix]# rpm -qa | grep postfix(該命令由後期補充所以主機名與筆記不一致)
postfix-2.10.1-6.el7.x86_64 ##存在該軟件
[root@jetslinux postfix]#
vim /etc/postfix/main.cf
76 myhostname = mailwestos.westos.com ##主機名
83 mydomain = westos.com ##域名
99 myorigin = $mydomain
113 inet_interfaces = all ##此功能爲接收從遠程主機發送的本地郵件(默認只能接收本地用戶)
114 #inet_interfaces = $myhostname
115 #inet_interfaces = $myhostname, localhost
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost
1.3 郵件羣發或別名發送
虛擬機2設置:
56 vim /etc/aliases
.....
admin: root ##別名發送
more: :include:/etc/postfix/users ##羣發
.....
57 postalias /etc/aliases ##編輯完上面文件,必須對其進行加密
58 cd /etc/postfix/
60 vim users
61 mail more ##羣發
63 mail -u student ##查看用戶student郵箱
64 mail admin ##別名發送
虛擬機2設置:
68 vim /etc/postfix/virtual
[email protected] (假域名) [email protected](真域名)
@qq.com @linux.com
69 postmap /etc/postfix/virtual ##加密
70 postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual" ##加密
71 ls
virtual.db
72 mail [email protected]
77 systemctl restart postfix.service
78 mail [email protected]
79 mail -u student ##查看郵箱student
使用虛擬機1:
mail [email protected] ##模擬給qq發郵件
1.5 出站地址僞裝
虛擬機2中的設置:
32 vim /etc/postfix/generic
[email protected](true) [email protected]
33 postmap /etc/postfix/generic
34 postconf -d | grep generic
35 postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
36 systemctl restart postfix.service
37 mail [email protected] ##模擬給westos回覆郵件,可注意到恢復人是[email protected]
虛擬機1中的設置:(這樣設置可以發送郵件給qq域名)
87 vim /etc/named.rfc1912.zones
.....
zone "qq.com" IN {
type master;
file "qq.com.zone";
allow-update { none; };
};
.....
89 cd /var/named/
92 cp -p linux.com.zone qq.com.zone
93 vim qq.com.zone
$TTL 1D
@ IN SOA dns.qq.com. root.qq.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.qq.com.
dns A 172.25.254.25
qq.com. MX 1 172.25.254.26.
94 systemctl restart named
95 mail [email protected]
【postqueue -f 再次立即發送所有隊列中的郵件】
1.6 遠程收發郵件
遠端客戶端:(真機做測試)
869 yum install telnet -y ##安裝遠程發送郵件
870 systemctl start telnet
871 telnet 172.25.254.26 25
[root@foundation24 Desktop]# telnet 172.25.254.26 25
Trying 172.25.254.26...
Connected to 172.25.254.26.
Escape character is '^]'.
220 maillinux.linux.com ESMTP Postfix
ehlo hello ##聞訊語句,測試是否連通
250-maillinux.linux.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:[email protected] ##發件人
250 2.1.0 Ok
rcpt to:[email protected] ##收件人
250 2.1.5 Ok
data ##輸入
354 End data with <CR><LF>.<CR><LF>
woshi24 ##郵件內容
.
250 2.0.0 Ok: queued as 38DA017E856
quit ##退出
221 2.0.0 Bye
虛擬機2設置:
41 yum install dovecot -y
42 vim /etc/dovecot/dovecot.conf
......
24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0
49 disable_plaintext_auth = no
......
43 vim /etc/dovecot/conf.d/10-mail.conf
.......
mail_location = mbox:~/mail:INBOX=/var/mail/%u
.......
44 mail -u student ##查看student用戶有無郵件可供測試
45 mail [email protected] ##自己給自己發送郵件
46 mail -u student
47 su - student
48 systemctl restart dovecot ##重啓服務
student用戶下:
1 cd /home/student/
2 ls
3 mkdir mail/.imap
4 mkdir -p mail/.imap
5 ls
6 cd mail/
7 ls
8 cd .imap/
9 touch INBOX
真機測試:
872 yum install mutt -y
876 mutt -f pop://[email protected] ##可查看虛擬機2上的student郵箱
[root@foundation66 software]# yum install thunderbird-31.2.0-1.el7.x86_64.rpm -y
新用戶的建立:
2. 創建虛擬郵箱帳號
2.1 安裝數據庫
虛擬機2設置:
56 yum install mariadb-server.x86_64 httpd php php-mysql -y
57 systemctl start mariadb
58 vim /etc/my.cnf
.....
skip-networking=1
.....
59 mysql_secure_installation ##設置數據庫登陸密碼
60 systemctl restart mariadb.service
61 cd /var/www/html/
62 yum install lftp -y ##安裝此命令,是爲了從主機上獲得數據庫插件
65 tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2
67 rm -fr phpMyAdmin-3.4.0-all-languages.tar.bz2
69 mv phpMyAdmin-3.4.0-all-languages/ mysqladmin ##將文件重命名,便於識記
71 cd mysqladmin/
72 cp config.sample.inc.php config.inc.php
73 vim config.inc.php ##裏面的上引號內容可以隨便填寫
74 systemctl restart httpd
75 mysql -uroot -p
MariaDB [(none)]> create user postfix@localhost identified by 'postfix'; ##創建用戶
MariaDB [(none)]> GRANT INSERT,SELECT on email.* to postfix@localhost; ##給用戶授權
78 cd /etc/postfix/
79 ls
80 vim mysql-user.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = username
where_field = username
81 cp mysql-user.cf mysql-domain.cf
82 vim mysql-domain.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = domain
where_field = domain
83 cp mysql-user.cf mysql-mailbox.cf
84 vim mysql-mailbox.cf
hosts = localhost
user = postfix
password = postfix
dbname = email
table = mailuser
select_field = maildir
where_field = username
85 postmap -q "[email protected]" mysql:/etc/postfix/mysql-user.cf
86 postmap -q "[email protected]" mysql:/etc/postfix/mysql-mailbox.cf
87 postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
測試上述文件是否起作用:
【
[root@maillinux postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mysql-user.cf
[email protected]
[root@maillinux postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mysql-mailbox.cf
/var/spool/redhat.co
[root@maillinux postfix]# postmap -q "redhat.com" mysql:/etc/postfix/mysql-domain.cf
redhat.com
】
2.3 遠程發送
虛擬機2設置:
【
cd /etc/skel/
3 mkdir -p mail/.imap
4 ls
5 cd mail/
6 ls
7 cd .imap/
8 touch INBOX
】 ##這些操作保證新建用戶可以自動建立/home/username/mail
14 vim /etc/postfix/main.cf
刪掉之前建立的最後兩行
15 postconf -e "virtual_mailbox_base = /home/vmail"
16 postconf -e "virtual_gid_maps = static:888"
17 postconf -e "virtual_uid_maps = static:888"
18 postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"
19 postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"
20 postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailbox.cf"
22 mail [email protected]
24 cd redhat.com/admin/new
31 cat 1489223524.Vfd01I280f499M802004.maillinux.linux.com
虛擬機2設置:
23 yum install dovecot-mysql.x86_64 -y
24 vim /etc/dovecot/dovecot.conf
.....
48 login_trusted_networks = 0.0.0.0/0 ##允許訪問網絡地址
49 disable_plaintext_auth = no ##開啓明文認證
......
25 vim /etc/dovecot/conf.d/10-auth.conf
123 !include auth-sql.conf.ext ##開啓數據庫認證
26 cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
27 cd /etc/dovecot/
29 vim dovecot-sql.conf.ext (該文件內容,關於數據庫信息,以自己建立的數據庫信息爲準)
32 driver = mysql
71 connect = host=localhost dbname=email(自己建立的數據庫名字) user=postfix(上述新建用戶) password=postfix
78 default_pass_scheme = PLAIN ##加密方式
107 password_query = \
108 SELECT username, domain, password \
109 FROM mailuser WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 888 AS uid, 888 AS gid FROM mailuser WHERE username = '%u'
30 vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n
31 systemctl start dovecot
真機測試登陸:
[root@foundation24 Desktop]# telnet 172.25.254.26 110
Trying 172.25.254.26...
Connected to 172.25.254.26.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user [email protected]
+OK
pass 123
+OK Logged in.
而後在雷鳥上登陸創建用戶,查收郵件
在數據庫中新加入用戶信息,而後在雷鳥上創建該用戶,在數據庫中增添用戶,切忌不可與本機存在的域名重複