mail
首先把两个虚拟机重置,确保环境绝对纯净。
并配置ip和yum源
要先安装dns(bind)
#######################
#### postfix #################################
1.
postfix提供smtp协议用来投递邮件
默认端口25
/var/log/maillog ##服务日志
mail root@westos.com
Subject: hello
hello world
. #用"."来结束录入内容并发送
mailq ##查看邮件队列
postqueue -f ##重新处理邮件队列
默认情况下邮件端口只在127.0.0.1上开启
2.
配置(两边都要配置,qq端就是把westos都换为qq)
vim /etc/postfix/main.cf
116 inet_interfaces = all ##25端口开启的网络接口
76 myhostname = westos-mail.westos.com ##指定mta主机名称
83 mydomain = westos.com ##指定mta的域名
99 myorigin = westos.com ##指定邮件来源结尾(@后面的字符内容)
164 mydestination = $myhostname, $mydomain, localhost ##接收邮件结尾字符的指定
systemctl restart postfix.service
systemctl stop firewalld
------------------------------------------------------------------------
------------------------------------------------------------------------
westos端
1 hostname server
2 yum install bind -y
3 systemctl start named
4* systemctl stop firewalld.service
5 vim /etc/named.conf
6 vim /etc/named.rfc1912.zones
8 ls
9 cp -p named.localhost westos.com.zone
10 vim westos.com.zone
12 vim qq.com.zone
13 systemctl restart named
14 ifconfig
18 dig -t mx qq.com
19 dig -t mx westos.com
20 systemctl disable firewalld.service
21 mail root@qq.com
22 mailq
23 netstat -antlpe |grep master
24 vim /etc/postfix/main.cf
25 systemctl restart postfix.service
26 mailq
29 postqueue -f
30 mailq
31 vim /etc/postfix/main.cf
32 systemctl restart postfix.service
33 mail root@westos.com
34 mailq
35 postqueue -f
36 mailq
37 mail
38 history
qq端
1 hostname desktop
2 vim /etc/resolv.conf
4 dig -t mx westos.com
5 systemctl stop firewalld.service
6 systemctl disable firewalld.service
8 mailq
9 mail
10 > /var/log/maillog
11 mailq
12 vim /etc/postfix/main.cf
13 systemctl restart postfix.service
14 mail
15 mail root@qq.com
16 mail root@westos.com
17 mail
18 history
westos端:
[root@westos-mail ~]# yum install bind -y
Loaded plugins: langpacks
Resolving Dependencies
Dependency Updated:
bind-libs.x86_64 32:9.9.4-29.el7 bind-libs-lite.x86_64 32:9.9.4-29.el7
bind-license.noarch 32:9.9.4-29.el7
Complete!
[root@westos-mail ~]# systemctl start named
[root@westos-mail ~]# systemctl stop firewalld.service
[root@westos-mail ~]# vim /etc/named.conf
[root@westos-mail ~]# vim /etc/named.rfc1912.zones
[root@westos-mail ~]# cd /var/named/
[root@westos-mail named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@westos-mail named]# cp -p named.localhost westos.com.zone
[root@westos-mail named]# vim westos.com.zone
[root@westos-mail named]# cp -p westos.com.zone qq.com.zone
[root@westos-mail named]# vim qq.com.zone
[root@westos-mail named]# systemctl restart named
[root@westos-mail named]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.244 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::5054:ff:fe00:2c0b prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:2c:0b txqueuelen 1000 (Ethernet)
RX packets 38492 bytes 667914217 (636.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30857 bytes 2197808 (2.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 2552 bytes 220272 (215.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2552 bytes 220272 (215.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@westos-mail named]# dig -t mx qq.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -t mx qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20740
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;qq.com. IN MX
;; ANSWER SECTION:
qq.com. 86400 IN MX 1 172.25.254.144.
;; AUTHORITY SECTION:
qq.com. 86400 IN NS dns.qq.com.
;; ADDITIONAL SECTION:
dns.qq.com. 86400 IN A 172.25.254.244
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed May 24 14:22:38 EDT 2017
;; MSG SIZE rcvd: 99
[root@westos-mail named]# dig -t mx westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -t mx westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34102
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;westos.com. IN MX
;; ANSWER SECTION:
westos.com. 86400 IN MX 1 172.25.254.244.
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 172.25.254.244
;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed May 24 14:22:43 EDT 2017
;; MSG SIZE rcvd: 103
[root@westos-mail named]# systemctl disable firewalld.service
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
[root@westos-mail named]# mail root@qq.com
Subject: qqqqq
qqqqq
qqqqq
.
EOT
[root@westos-mail named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B 449 Wed May 24 14:24:29 root@westos-mail.westos.com
(connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
root@qq.com
-- 0 Kbytes in 1 Request.
[root@westos-mail named]# netstat -antlpe |grep master
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 0 24460 1392/master
tcp6 0 0 ::1:25 :::* LISTEN 0 24461 1392/master
[root@westos-mail named]# vim /etc/postfix/main.cf
[root@westos-mail named]# 116 inet interfaces = all^C
[root@westos-mail named]# systemctl restart postfix.service
[root@westos-mail named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B 449 Wed May 24 14:24:29 root@westos-mail.westos.com
(connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
root@qq.com
-- 0 Kbytes in 1 Request.
[root@westos-mail named]# postqueue -f
[root@westos-mail named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B 449 Wed May 24 14:24:29 root@westos-mail.westos.com
(connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
root@qq.com
-- 0 Kbytes in 1 Request.
[root@westos-mail named]# postqueue -f
[root@westos-mail named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B 449 Wed May 24 14:24:29 root@westos-mail.westos.com
(connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
root@qq.com
-- 0 Kbytes in 1 Request.
[root@westos-mail named]#
[root@westos-mail named]#
[root@westos-mail named]#
[root@westos-mail named]#
[root@westos-mail named]#
[root@westos-mail named]# 邮件发不出去,继续配置文件
[root@westos-mail named]# vim /etc/postfix/main.cf
[root@westos-mail named]# systemctl restart postfix.service
[root@westos-mail named]# mail root@westos.com
Subject: aaa
aaa
aaa
.
EOT
[root@westos-mail named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B 449 Wed May 24 14:24:29 root@westos-mail.westos.com
(connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
root@qq.com
-- 0 Kbytes in 1 Request.
You have mail in /var/spool/mail/root
[root@westos-mail named]# postqueue -f
[root@westos-mail named]# mailq
Mail queue is empty
[root@westos-mail named]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 root Wed May 24 14:45 19/559 "aaa"
& 1
Message 1:
From root@westos.com Wed May 24 14:45:58 2017
Return-Path: <root@westos.com>
X-Original-To: root@westos.com
Delivered-To: root@westos.com
Date: Wed, 24 May 2017 14:45:58 -0400
To: root@westos.com
Subject: aaa
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@westos.com (root)
Status: R
aaa
aaa
& Held 1 message in /var/spool/mail/root
[root@westos-mail named]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 2 messages 1 new
1 root Wed May 24 14:45 20/570 "aaa"
>N 2 root Wed May 24 14:48 21/710 "xxx"
& 2
Message 2:
From root@qq.com Wed May 24 14:48:34 2017
Return-Path: <root@qq.com>
X-Original-To: root@westos.com
Delivered-To: root@westos.com
Date: Wed, 24 May 2017 14:48:34 -0400
To: root@westos.com
Subject: xxx
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@qq.com (root)
Status: R
xxx
& Held 2 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root
[root@westos-mail named]#
~~~~~~~~~~~~~~~~~
qq端:
[root@qq-mail ~]# vim /etc/resolv.conf
[root@qq-mail ~]# dig -t mx qq.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -t mx qq.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38373
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;qq.com. IN MX
;; ANSWER SECTION:
qq.com. 86400 IN MX 1 172.25.254.144.
;; AUTHORITY SECTION:
qq.com. 86400 IN NS dns.qq.com.
;; ADDITIONAL SECTION:
dns.qq.com. 86400 IN A 172.25.254.244
;; Query time: 1 msec
;; SERVER: 172.25.254.244#53(172.25.254.244)
;; WHEN: Wed May 24 14:20:12 EDT 2017
;; MSG SIZE rcvd: 99
[root@qq-mail ~]# dig -t mx westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> -t mx westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3085
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;westos.com. IN MX
;; ANSWER SECTION:
westos.com. 86400 IN MX 1 172.25.254.244.
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 172.25.254.244
;; Query time: 0 msec
;; SERVER: 172.25.254.244#53(172.25.254.244)
;; WHEN: Wed May 24 14:20:18 EDT 2017
;; MSG SIZE rcvd: 103
[root@qq-mail ~]# systemctl stop firewalld.service
[root@qq-mail ~]# systemctl disable firewalld.service
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
[root@qq-mail ~]# mail q
Subject: ^C
EOT
No message, no subject; hope that's ok
[root@qq-mail ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
50CB217E84A 415 Wed May 24 14:29:40 root@qq-mail.qq.com
(user lookup error)
q@qq-mail.qq.com
-- 0 Kbytes in 1 Request.
[root@qq-mail ~]# mail
No mail for root
[root@qq-mail ~]# > /var/log/maillog
[root@qq-mail ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
50CB217E84A 415 Wed May 24 14:29:40 root@qq-mail.qq.com
(user lookup error)
q@qq-mail.qq.com
-- 0 Kbytes in 1 Request.
[root@qq-mail ~]#
[root@qq-mail ~]#
[root@qq-mail ~]#
[root@qq-mail ~]#
[root@qq-mail ~]#
[root@qq-mail ~]# vim /etc/postfix/main.cf
[root@qq-mail ~]# systemctl restart postfix.service
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 root Wed May 24 14:47 22/769 "qqqqq"
& 1
Message 1:
From root@westos-mail.westos.com Wed May 24 14:47:02 2017
Return-Path: <root@westos-mail.westos.com>
X-Original-To: root@qq.com
Delivered-To: root@qq.com
Date: Wed, 24 May 2017 14:24:29 -0400
To: root@qq.com
Subject: qqqqq
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@westos-mail.westos.com (root)
Status: R
qqqqq
qqqqq
& 2
2: Invalid message number
& Held 1 message in /var/spool/mail/root
You have mail in /var/spool/mail/root
[root@qq-mail ~]# mail root@qq.com
Subject: zzz
zzz
.
EOT
[root@qq-mail ~]# mail root@westos.com
Subject: xxx
xxx
.
EOT
You have new mail in /var/spool/mail/root
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 2 messages 1 new
1 root Wed May 24 14:47 23/780 "qqqqq"
>N 2 root Wed May 24 14:48 18/517 "zzz"
& 2
Message 2:
From root@qq.com Wed May 24 14:48:19 2017
Return-Path: <root@qq.com>
X-Original-To: root@qq.com
Delivered-To: root@qq.com
Date: Wed, 24 May 2017 14:48:19 -0400
To: root@qq.com
Subject: zzz
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@qq.com (root)
Status: R
zzz
& Held 2 messages in /var/spool/mail/root
[root@qq-mail ~]#
-------------------------------------------------------------------------
-------------------------------------------------------------------------
3.邮件别名
[root@qq-mail ~]# vim /etc/aliases
别名: 真名 ##邮件别名
别名: :include:filename ##邮件群发
vim filename
user1
user2
postalias /etc/aliases ##或下一行使更改的文件生效
systemctl restsrt postfix.service
mail 别名
qq端:
1 vim /etc/aliases
2 mail
3 cat /var/spool/mail/root
4 systemctl restart postfix.service
5 mail
6 history
[root@qq-mail ~]# systemctl restart postfix.service
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 3 messages 1 new
1 root Wed May 24 14:47 23/780 "qqqqq"
2 root Wed May 24 14:48 19/528 "zzz"
>N 3 root Wed May 24 15:40 21/752 "admin@qq.com.com.com"
& 3
Message 3:
From root@westos.com Wed May 24 15:40:20 2017
Return-Path: <root@westos.com>
X-Original-To: admin@qq.com
Delivered-To: admin@qq.com
Date: Wed, 24 May 2017 15:40:19 -0400
To: admin@qq.com
Subject: admin@qq.com.com.com
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@westos.com (root)
Status: R
& Held 3 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root
[root@qq-mail ~]#
~~~~~~~~~~~~~
westos端:
1 mail admin@qq.com
2 mailq
3 mail admin@qq.com
4 mail
5 history
-------------------------------------------------------------------------
qq端:
[root@qq-mail ~]# vim /etc/postfix/moreuser
[root@qq-mail ~]# cat /etc/postfix/moreuser
root
student
[root@qq-mail ~]# postalias /etc/aliases
westos端:
[root@westos-mail named]# mail moreuser@qq.com
Subject: student
root
moreuser
.
EOT
qq端:
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 4 messages 1 new
1 root Wed May 24 14:47 23/780 "qqqqq"
2 root Wed May 24 14:48 19/528 "zzz"
3 root Wed May 24 15:40 22/763 "admin@qq.com.com.com"
>N 4 root Wed May 24 20:20 25/870 "student"
& 4
Message 4:
From root@westos.com Wed May 24 20:20:44 2017
Return-Path: <root@westos.com>
X-Original-To: moreuser@qq.com
Delivered-To: root@qq.com
Delivered-To: moreuser@qq.com
Date: Wed, 24 May 2017 20:20:44 -0400
To: moreuser@qq.com
Subject: student
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@westos.com (root)
Status: R
root
moreuser
& Held 4 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root
[root@qq-mail ~]# su - student
[student@qq-mail ~]$ mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/student": 1 message 1 new
>N 1 root Wed May 24 20:20 25/873 "student"
& 1
Message 1:
From root@westos.com Wed May 24 20:20:44 2017
Return-Path: <root@westos.com>
X-Original-To: moreuser@qq.com
Delivered-To: student@qq.com
Delivered-To: moreuser@qq.com
Date: Wed, 24 May 2017 20:20:44 -0400
To: moreuser@qq.com
Subject: student
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@westos.com (root)
Status: R
root
moreuser
&
-------------------------------------------------------------------------
-------------------------------------------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.通过远程主机测试邮件服务
-------------------------------------------------------------------------
[root@foundation44 ~]# yum install telnet -y
[root@foundation44 ~]# telnet 172.25.254.244 25
Trying 172.25.254.244...
Connected to 172.25.254.244.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
ehlo hello
250-westos-mail.westos.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:root@westos.com
250 2.1.0 Ok
rcpt to:root@qq.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
telnettelnet
telnet
.
250 2.0.0 Ok: queued as 42B03EAC27
qq端:
[root@qq-mail ~]# mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/root": 5 messages 1 new
1 root Wed May 24 14:47 23/780 "qqqqq"
2 root Wed May 24 14:48 19/528 "zzz"
3 root Wed May 24 15:40 22/763 "admin@qq.com.com.com"
4 root Wed May 24 20:20 26/881 "student"
>N 5 root@westos.com Wed May 24 20:40 14/498
& 5
Message 5:
From root@westos.com Wed May 24 20:40:15 2017
Return-Path: <root@westos.com>
X-Original-To: root@qq.com
Delivered-To: root@qq.com
Status: R
telnettelnet
telnet
&
-------------------------------------------------------------------------
5.邮件客户端的访问控制
#限制客户端
在mta(因特网邮件传送代理)上
postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"
vim /etc/postfix/access ##在最末尾重启一行加上下面内容
172.25.254.44 REJECT
postmap /etc/postfix/access
systemctl restart postfix
测试
[root@foundation44 ~]# telnet 172.25.254.244 25
Trying 172.25.254.244...
Connected to 172.25.254.244.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:root@westos.com
250 2.1.0 Ok
rcpt to:root@qq.com
554 5.7.1 <unknown[172.25.254.44]>: Client host rejected: Access denied
~~~~~~~~~~~~~
##限制用户发送
postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"
vim /etc/postfix/sender
student@westos.com REJECT
postmap /etc/postfix/sender
systemctl restart postfix
测试
[root@foundation44 ~]# telnet 172.25.254.244 25
Trying 172.25.254.244...
Connected to 172.25.254.244.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:student@westos.com
250 2.1.0 Ok
rcpt to:root@westos.com
554 5.7.1 <student@westos.com>: Sender address rejected: Access denied
~~~~~~~~~~~~~
##限制用户接收
postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"
vim /etc/postfix/recip
student@westos.com REJECT
postmap /etc/postfix/recip
systemctl restart postfix
测试
[root@foundation44 ~]# telnet 172.25.254.244 25
Trying 172.25.254.244...
Connected to 172.25.254.244.
Escape character is '^]'.
220 westos-mail.westos.com ESMTP Postfix
mail from:westos@westos.com
250 2.1.0 Ok
rcpt to:root@westos.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
lalalalalala
lalalalalala
.
250 2.0.0 Ok: queued as CB0B8EAC27
mail from:root@westos.com
250 2.1.0 Ok
rcpt to:westos@westos.com
554 5.7.1 <westos@westos.com>: Recipient address rejected: Access denied
~~~~~~~~~~~~~~
##出站地址伪装
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
vim /etc/postfix/generic ##最后另起一行添加以下内容
student@westos.com hello@yuyang.com
postmap /etc/postfix/generic
systemctl restart postfix
测试
su - student
mail root@qq.com
结果:
Message 6:
From hello@yuyang.com Wed May 24 22:05:20 2017
Return-Path: <hello@yuyang.com>
X-Original-To: root@qq.com
Delivered-To: root@qq.com
Date: Wed, 24 May 2017 22:05:19 -0400
To: root@qq.com
Subject: yuyanghello
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: hello@yuyang.com (Student User)
Status: R
~~~~~~~~~~~~~~~
##入站地址转换
dns mx 记录解析先做好
[root@westos-mail ~]# cd /var/named/
[root@westos-mail named]# ls
data named.ca named.localhost qq.com.zone westos.com.zone
dynamic named.empty named.loopback slaves
[root@westos-mail named]# cp -p qq.com.zone yuyang.com.zone
[root@westos-mail named]# vim yuyang.com.zone
[root@westos-mail named]# cat yuyang.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.244
yuyang.com. MX 1 172.25.254.244.
--------------------------------------
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
vim /etc/postfix/virtual
虚拟名字 真实用户
hello@yuyang.com student@westos.com
postmap /etc/postfix/virtual
systemctl restart postfix
测试
mail hello@yuyang.com
结果图:
##########################
####### dovecot ##########
##########################
1.
/etc/services ##文件中提供了所有服务及对应的端口
/etc/shells
/etc/skel ##用户骨架文件,所有新建用户家目录都和它的结构相同
dovecot 用来提供收件协议
pop3 端口110
imap 端口143
imaps 端口993
pop3s 端口995
给定用户名称,用户密码,dovecot程序代我们去看这个用户的邮件文件
2.
yum install dovecot -y ##安装邮件接收服务
3.
vim /etc/dovecot/dovecot.conf
24 protocols = imap pop3 lmtp
48 login_trusted_networks = 0.0.0.0/0
49 disable_plaintext_auth = no
vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
systemctl restart dovecot
测试准备:
[root@westos-mail named]# su - student ##进入测试用户
Last login: Thu May 25 10:05:48 EDT 2017 on pts/0
[student@westos-mail ~]$ mkdir mail/.imap -p
[student@westos-mail ~]$ touch mail/.imap/INBOX ##建立存放文件
远程登陆测试:
[root@foundation44 Desktop]# yum install mutt -y
[root@foundation44 Desktop]# mutt -f pop://student@172.25.254.244
#########################
#### postfix+mariadb ####
#########################
1.
随便一个端(这里是qq端):
yum install thunderbird-31.2.0-1.el7.x86_64.rpm -y
打开thunderbird
[root@westos-mail ~] mv /etc/postfix/main.cf /mnt/
[root@westos-mail ~]# yum reinstall postfix.x86_64 -y
[root@westos-mail mnt]# vim /etc/postfix/main.cf
75 myhostname = westos-mail.westos.com
83 mydomain = westos.com
99 myorigin = $mydomain
113 inet_interfaces = all
116 #inet_interfaces = localhost
164 mydestination = $myhostname, $mydomain, localhost
[root@westos-mail mnt]# systemctl restart postfix.service
[root@westos-mail mnt]# yum install httpd php php-mysql mariadb-server -y
[root@westos-mail mnt]# systemctl start mariadb
[root@westos-mail mnt]# vim /etc/my.cnf
10 skip-networking=1
[root@westos-mail mnt]# systemctl restart postfix.service
[root@westos-mail mnt]# systemctl restart mariadb.service
[root@westos-mail mnt]# mysql_secure_installation
配置mysql...
[root@westos-mail Desktop]# cd /var/www/html/
[root@westos-mail html]# ls
phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@westos-mail html]# tar jfx phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@westos-mail html]# ls
phpMyAdmin-3.4.0-all-languages phpMyAdmin-3.4.0-all-languages.tar.bz2
[root@westos-mail html]# rm -fr *.bz2
[root@westos-mail html]# ls
phpMyAdmin-3.4.0-all-languages
[root@westos-mail html]# mv phpMyAdmin-3.4.0-all-languages/ myadmin
[root@westos-mail html]# ls
myadmin
[root@westos-mail html]# cd myadmin/
[root@westos-mail myadmin]# ls
......
[root@westos-mail myadmin]# vim config.sample.inc.php config.inc.php
2 files to edit
[root@westos-mail myadmin]# vim config.sample.inc.php config.inc.php
2 files to edit
[root@westos-mail myadmin]# vim config.sample.inc.php
[root@westos-mail myadmin]# vim config.inc.php
[root@westos-mail myadmin]# cp config.sample.inc.php config.inc.php
[root@westos-mail myadmin]# vim config.inc.php
17 行单引号中不为空就可以,我填的是mysql
[root@westos-mail myadmin]# systemctl restart httpd
测试:在随便一台基于172.25.254.244的主机上(配置了nameserver的)
[root@westos-mail myadmin]# mysql -uroot -p123
MariaDB [(none)]> create user postuser@localhost identified by 'postuser';
MariaDB [(none)]> grant select,update,insert on email.* to postuser@localhost;
MariaDB [(none)]> quit
Bye
[root@westos-mail myadmin]# mysql -upostuser -ppostuser
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select * from email.emailuser
-> ;
+-------------+----------+---------+---------------+
| username | password | domain | maildir |
+-------------+----------+---------+---------------+
| lee@lee.com | lee | lee.com | /lee.com/lee/ |
+-------------+----------+---------+---------------+
1 row in set (0.00 sec)
quit
[root@westos-mail myadmin]# cd /etc/postfix/
[root@westos-mail postfix]# ls
access generic main.cf recip.db sender.db virtual.db
access.db generic.db master.cf relocated transport
canonical header_checks recip sender virtual
[root@westos-mail postfix]# vim mailuser.cf ##用户名称查询
host = localhost ##登陆数据库所在主机
user = postuser ##登陆数据库的用户
password = postuser ##登陆数据库的密码
dbname = email ##postfix要查询的名称
table = emailuser ##postfix要查询的表的名称
select_field = username ##postfix要查询的字段
where_field = username ##用户给定postfix的查询条件
[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailuser.cf
lee@lee.com
[root@westos-mail postfix]# cp mailuser.cf maildomain.cf
[root@westos-mail postfix]# ls
access generic maildomain.cf master.cf relocated transport
access.db generic.db mailuser.cf recip sender virtual
canonical header_checks main.cf recip.db sender.db virtual.db
[root@westos-mail postfix]# vim maildomain.cf ##用户域名查询
host = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
[root@westos-mail postfix]# postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf
lee.com
[root@westos-mail postfix]# vim /etc/postfix/mailbox.cf ##用户邮箱位置查询
host = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
[root@westos-mail postfix]# postmap -q "lee@lee.com" mysql:/etc/postfix/mailbox.cf
/lee.com/lee/
###配置postfix
groupadd -g 666 vmail
useradd -s /sbin/nologin -u 666 vmail -g 666
postconf -e "virtual_mailbox_base = /home/vmail" ##设定虚拟用户的邮件目录
postconf -e "virtual_uid_maps = static:666" ##虚拟用户建立文件的uid
postconf -e "virtual_gid_maps = static:666" ##虚拟用户建立文件的gid
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/maildomain.cf"
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"
systemctl restart postfix
#########################
#### dovecot+mariadb ####
#########################
[root@westos ~]# yum install dovecot dovecot-mysql -y ##dovecot-mysql是dovecot软件的插件,可以识别mysql
[root@westos ~]# vim /etc/dovecot/dovecot.conf ##主配置文件
24 protocols = imap pop3 lmtp ##支持的认证方式 lmtp-加密协议
48 login_trusted_networks = 0.0.0.0/0 ##信任网络(允许谁连接) 0.0.0.0/0(=all)
49 disable_plaintext_auth = no ##允许铭文认证
[root@westos ~]# vim /etc/dovecot/conf.d/10-auth.conf
123 !include auth-sql.conf.ext ##开启mysql认证方式
#生成dovecot读取mysql的配置
[root@westos ~]# cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
[root@westos ~]# vim /etc/dovecot/dovecot-sql.conf.ext
32 driver = mysql
71 connect = host=localhost dbname=emailuser user=postuser password=postuser ##查询时用到的库
78 default_pass_scheme = PLAIN
107 password_query = \ ##查询密码匹配
108 SELECT username, domain, password \
109 FROM emailuser WHERE username = '%u' AND domain = '%d'
125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM emailuser WHERE use rname = '%u' ##查询邮件内容
[root@westos ~]# vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n ##指定邮件位置
168 first_valid_uid = 666 ##指定邮件文件查询的用户身份
175 first_valid_gid = 666
[root@westos ~]# systemctl restart dovecot
【测试】
[root@westos ~]# telnet 172.25.254.224 110
Trying 172.25.254.224...
Connected to 172.25.254.224.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user haha@yuyang.com
+OK
pass 123
+OK Logged in.
quit
########################
#### postfix空壳邮件 ####
########################
重置虚拟机
配置网络和yum源
重启网络
vim /etc/postfix/main.cf
前面配置相同
mydestination =
316 relayhost = 172.25.254.105(实际接收方的地址)
systemctl restart postfix.service
给空壳发送邮件进行测试
空壳接受不到(但是发件方发送给的使空壳)实际接受方才能接收到
(配置个dns会更清楚看出效果(dig到的地址是空壳的))
76 myhostname = nullmail.example.com
83 mydomain = example.com
99 myorigin = westos.com ##172.25.254.224的域名
113 inet_interfaces = all
164 mydestination =
316 relayhost = 172.25.254.224
[root@nullmail ~]# systemctl restart postfix
测试:
[root@nullmail ~]# mail root
[root@nullmail ~]# mail
[root@westos ~]# mail