mail
首先把两个虚拟机重置,确保环境绝对纯净。
并配置ip和yum源
要先安装dns(bind)


#######################

#### postfix ##########
#######################
1.
postfix提供smtp协议用来投递邮件
默认端口25
/var/log/maillog ##服务日志
mail [email protected]
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 

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

    6  vim /etc/named.rfc1912.zones

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件 

    7  cd /var/named/
    8  ls
    9  cp -p named.localhost westos.com.zone

   10  vim westos.com.zone 

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

   11  cp -p westos.com.zone qq.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 [email protected]
   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 [email protected]
   34  mailq
   35  postqueue -f
   36  mailq
   37  mail
   38  history
qq端
    1  hostname desktop

    2  vim /etc/resolv.conf 

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

    3  dig -t mx qq.com
    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 [email protected]
   16  mail [email protected]
   17  mail
   18  history




westos端:
[[email protected] ~]# 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!
[[email protected] ~]# systemctl start named
[[email protected] ~]# systemctl stop firewalld.service 
[[email protected] ~]# vim /etc/named.conf 
[[email protected] ~]# vim /etc/named.rfc1912.zones 
[[email protected] ~]# cd /var/named/
[[email protected] named]# ls
data  dynamic  named.ca  named.empty  named.localhost  named.loopback  slaves
[[email protected] named]# cp -p named.localhost westos.com.zone
[[email protected] named]# vim westos.com.zone 
[[email protected] named]# cp -p westos.com.zone qq.com.zone 
[[email protected] named]# vim qq.com.zone 
[[email protected] named]# systemctl restart named
[[email protected] 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


[[email protected] 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. 86400INA 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


[[email protected] 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. INMX


;; ANSWER SECTION:
westos.com. 86400INMX 1 172.25.254.244.


;; AUTHORITY SECTION:
westos.com. 86400INNS dns.westos.com.


;; ADDITIONAL SECTION:
dns.westos.com. 86400INA 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


[[email protected] named]# systemctl disable firewalld.service
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
[[email protected] named]# mail [email protected]
Subject: qqqqq
qqqqq
qqqqq
.
EOT
[[email protected] named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B      449 Wed May 24 14:24:29  [email protected]
            (connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
                                         [email protected]


-- 0 Kbytes in 1 Request.
[[email protected] 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         
[[email protected] named]# vim /etc/postfix/main.cf 
[[email protected] named]# 116 inet interfaces = all^C
[[email protected] named]# systemctl restart postfix.service 
[[email protected] named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B      449 Wed May 24 14:24:29  [email protected]
            (connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
                                         [email protected]


-- 0 Kbytes in 1 Request.
[[email protected] named]# postqueue -f
[[email protected] named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B      449 Wed May 24 14:24:29  [email protected]
            (connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
                                         [email protected]


-- 0 Kbytes in 1 Request.
[[email protected] named]# postqueue -f
[[email protected] named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B      449 Wed May 24 14:24:29  [email protected]
            (connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
                                         [email protected]


-- 0 Kbytes in 1 Request.
[[email protected] named]# 
[[email protected] named]# 
[[email protected] named]# 
[[email protected] named]# 
[[email protected] named]# 
[[email protected] named]# 邮件发不出去,继续配置文件
[[email protected] named]# vim /etc/postfix/main.cf 
[[email protected] named]# systemctl restart postfix.service 
[[email protected] named]# mail [email protected]
Subject: aaa
aaa
aaa 
.
EOT
[[email protected] named]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A24A24628B      449 Wed May 24 14:24:29  [email protected]
            (connect to 172.25.254.144[172.25.254.144]:25: Connection refused)
                                         [email protected]


-- 0 Kbytes in 1 Request.
You have mail in /var/spool/mail/root
[[email protected] named]# postqueue -f
[[email protected] named]# mailq
Mail queue is empty
[[email protected] 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 [email protected]  Wed May 24 14:45:58 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 24 May 2017 14:45:58 -0400
To: [email protected]
Subject: aaa
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R


aaa
aaa


& Held 1 message in /var/spool/mail/root
[[email protected] 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 [email protected]  Wed May 24 14:48:34 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 24 May 2017 14:48:34 -0400
To: [email protected]
Subject: xxx
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R


xxx


& Held 2 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root
[[email protected] named]# 
~~~~~~~~~~~~~~~~~
qq端:
[[email protected] ~]# vim /etc/resolv.conf 
[[email protected] ~]# 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. 86400INA 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


[[email protected] ~]# 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. INMX


;; ANSWER SECTION:
westos.com. 86400INMX 1 172.25.254.244.


;; AUTHORITY SECTION:
westos.com. 86400INNS dns.westos.com.


;; ADDITIONAL SECTION:
dns.westos.com. 86400INA 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


[[email protected] ~]# systemctl stop firewalld.service 
[[email protected] ~]# systemctl disable firewalld.service 
rm '/etc/systemd/system/basic.target.wants/firewalld.service'
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
[[email protected] ~]# mail q
Subject: ^C
EOT
No message, no subject; hope that's ok
[ro[email protected] ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
50CB217E84A      415 Wed May 24 14:29:40  [email protected]
                                                           (user lookup error)
                                         [email protected]


-- 0 Kbytes in 1 Request.
[[email protected] ~]# mail
No mail for root
[[email protected] ~]# > /var/log/maillog 
[[email protected] ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
50CB217E84A      415 Wed May 24 14:29:40  [email protected]
                                                           (user lookup error)
                                         [email protected]


-- 0 Kbytes in 1 Request.
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# vim /etc/postfix/main.cf 
[[email protected] ~]# systemctl restart postfix.service 
[[email protected] ~]# 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 [email protected]  Wed May 24 14:47:02 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 24 May 2017 14:24:29 -0400
To: [email protected]
Subject: qqqqq
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (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
[[email protected] ~]# mail [email protected]
Subject: zzz
zzz
.
EOT
[[email protected] ~]# mail [email protected]
Subject: xxx
xxx
.
EOT
You have new mail in /var/spool/mail/root
[[email protected] ~]# 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 [email protected]  Wed May 24 14:48:19 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 24 May 2017 14:48:19 -0400
To: [email protected]
Subject: zzz
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R


zzz


& Held 2 messages in /var/spool/mail/root
[[email protected] ~]# 
-------------------------------------------------------------------------
-------------------------------------------------------------------------










3.邮件别名
[[email protected] ~]# vim /etc/aliases
别名: 真名 ##邮件别名
别名: :include:filename##邮件群发


vim filename
user1
user2
mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

postalias /etc/aliases ##或下一行使更改的文件生效
systemctl restsrt postfix.service

mail 别名

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

-------------------------------------------------------------------------
qq端:
    1  vim /etc/aliases
    2  mail
    3  cat /var/spool/mail/root
    4  systemctl restart postfix.service 
    5  mail
    6  history


[[email protected] ~]# systemctl restart postfix.service 
[[email protected] ~]# 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   "[email protected]"
& 3
Message  3:
From [email protected]  Wed May 24 15:40:20 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 24 May 2017 15:40:19 -0400
To: [email protected]
Subject: [email protected]
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R




& Held 3 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root
[[email protected] ~]# 
~~~~~~~~~~~~~
westos端:
    1  mail [email protected]
    2  mailq
    3  mail [email protected]
    4  mail
    5  history
-------------------------------------------------------------------------
qq端:
[[email protected] ~]# vim /etc/postfix/moreuser
[[email protected] ~]# cat /etc/postfix/moreuser
root
student
[[email protected] ~]# postalias /etc/aliases
westos端:
[[email protected] named]# mail [email protected]
Subject: student
root
moreuser
.
EOT
qq端:
[[email protected] ~]# 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   "[email protected]"
>N  4 root                  Wed May 24 20:20  25/870   "student"
& 4
Message  4:
From [email protected]  Wed May 24 20:20:44 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 24 May 2017 20:20:44 -0400
To: [email protected]
Subject: student
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R


root
moreuser


& Held 4 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root
[[email protected] ~]# su - student
[[email protected] ~]$ 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 [email protected]  Wed May 24 20:20:44 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 24 May 2017 20:20:44 -0400
To: [email protected]
Subject: student
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R


root
moreuser





-------------------------------------------------------------------------
-------------------------------------------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^








4.通过远程主机测试邮件服务
-------------------------------------------------------------------------
[[email protected] ~]# yum install telnet -y
[[email protected] ~]# 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:[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>
telnettelnet
telnet
.
250 2.0.0 Ok: queued as 42B03EAC27


qq端:
[[email protected] ~]# 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   "[email protected]"
    4 root                  Wed May 24 20:20  26/881   "student"
>N  5 [email protected]       Wed May 24 20:40  14/498   
& 5
Message  5:
From [email protected]  Wed May 24 20:40:15 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
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


测试
[[email protected] ~]# 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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
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
[email protected] REJECT


postmap  /etc/postfix/sender
systemctl restart postfix


测试
[[email protected] ~]# 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:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <[email protected]>: Sender address rejected: Access denied
~~~~~~~~~~~~~


##限制用户接收
postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"


vim /etc/postfix/recip
[email protected] REJECT


postmap /etc/postfix/recip


systemctl restart postfix


测试


[[email protected] ~]# 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:[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>
lalalalalala
lalalalalala
.
250 2.0.0 Ok: queued as CB0B8EAC27
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <[email protected]>: Recipient address rejected: Access denied
~~~~~~~~~~~~~~


##出站地址伪装
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"


vim /etc/postfix/generic ##最后另起一行添加以下内容
[email protected] [email protected]


postmap /etc/postfix/generic
systemctl restart postfix


测试
su - student
mail [email protected]
结果:
Message  6:
From [email protected]  Wed May 24 22:05:20 2017
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Wed, 24 May 2017 22:05:19 -0400
To: [email protected]
Subject: yuyanghello
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (Student User)
Status: R
~~~~~~~~~~~~~~~


##入站地址转换

dns mx 记录解析先做好

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

[[email protected] named]# vim /etc/named.rfc1912.zones
[[email protected] ~]# cd /var/named/
[[email protected] named]# ls
data     named.ca     named.localhost  qq.com.zone  westos.com.zone
dynamic  named.empty  named.loopback   slaves
[[email protected] named]# cp -p qq.com.zone yuyang.com.zone
[[email protected] named]# vim yuyang.com.zone 
[[email protected] 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 1172.25.254.244.
-------------------------------------- 


postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
vim /etc/postfix/virtual
虚拟名字 真实用户
[email protected] [email protected]


postmap /etc/postfix/virtual
systemctl restart postfix


测试
mail [email protected]
结果图:
mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件














##########################
####### 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


测试准备:
[[email protected] named]# su - student ##进入测试用户
Last login: Thu May 25 10:05:48 EDT 2017 on pts/0
[[email protected] ~]$ mkdir mail/.imap -p
[[email protected] ~]$ touch mail/.imap/INBOX ##建立存放文件


远程登陆测试:
[[email protected] Desktop]# yum install mutt -y
[[email protected] Desktop]# mutt -f pop://[email protected]
mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件








#########################
#### postfix+mariadb ####
#########################
1.
随便一个端(这里是qq端):
yum install thunderbird-31.2.0-1.el7.x86_64.rpm -y
mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件
打开thunderbird
mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件











[[email protected] ~] mv /etc/postfix/main.cf /mnt/
[[email protected] ~]# yum reinstall postfix.x86_64 -y
[[email protected] 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
[[email protected] mnt]# systemctl restart postfix.service 
[[email protected] mnt]# yum install httpd php php-mysql mariadb-server -y
[[email protected] mnt]# systemctl start mariadb
[[email protected] mnt]# vim /etc/my.cnf
10 skip-networking=1
[[email protected] mnt]# systemctl restart postfix.service 
[[email protected] mnt]# systemctl restart mariadb.service 
[[email protected] mnt]# mysql_secure_installation 
配置mysql...
[[email protected] Desktop]# cd /var/www/html/
[[email protected] html]# ls
phpMyAdmin-3.4.0-all-languages.tar.bz2
[[email protected] html]# tar jfx phpMyAdmin-3.4.0-all-languages.tar.bz2 
[[email protected] html]# ls
phpMyAdmin-3.4.0-all-languages  phpMyAdmin-3.4.0-all-languages.tar.bz2
[[email protected] html]# rm -fr *.bz2
[[email protected] html]# ls
phpMyAdmin-3.4.0-all-languages
[[email protected] html]# mv phpMyAdmin-3.4.0-all-languages/ myadmin
[[email protected] html]# ls
myadmin
[[email protected] html]# cd myadmin/
[[email protected] myadmin]# ls
......
[[email protected] myadmin]# vim config.sample.inc.php config.inc.php 
2 files to edit
[[email protected] myadmin]# vim config.sample.inc.php config.inc.php 
2 files to edit
[[email protected] myadmin]# vim config.sample.inc.php
[[email protected] myadmin]# vim config.inc.php
[[email protected] myadmin]# cp config.sample.inc.php config.inc.php 
[[email protected] myadmin]# vim config.inc.php
17 行单引号中不为空就可以,我填的是mysql
[[email protected] myadmin]# systemctl restart httpd
测试:在随便一台基于172.25.254.244的主机上(配置了nameserver的)
mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件
[[email protected] myadmin]# mysql -uroot -p123
MariaDB [(none)]> create user [email protected] identified by 'postuser';
MariaDB [(none)]> grant select,update,insert on email.* to [email protected];
MariaDB [(none)]> quit
Bye
[[email protected] 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       |
+-------------+----------+---------+---------------+
| [email protected] | lee      | lee.com | /lee.com/lee/ |
+-------------+----------+---------+---------------+
1 row in set (0.00 sec)
quit


[[email protected] myadmin]# cd /etc/postfix/
[[email protected] 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
[[email protected] postfix]# vim mailuser.cf ##用户名称查询
host = localhost ##登陆数据库所在主机
user = postuser ##登陆数据库的用户
password = postuser ##登陆数据库的密码
dbname = email ##postfix要查询的名称
table = emailuser ##postfix要查询的表的名称
select_field = username ##postfix要查询的字段
where_field = username ##用户给定postfix的查询条件
[[email protected] postfix]# postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf 
[email protected]
[[email protected] postfix]# cp mailuser.cf maildomain.cf
[[email protected] 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
[[email protected] postfix]# vim maildomain.cf ##用户域名查询
host = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
[[email protected] postfix]# postmap -q "lee.com" mysql:/etc/postfix/maildomain.cf  
lee.com
[[email protected] postfix]# vim /etc/postfix/mailbox.cf##用户邮箱位置查询
host = localhost
user = postuser
password = postuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
[[email protected] postfix]# postmap -q "[email protected]" 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 ####
#########################

[[email protected] ~]# yum install dovecot dovecot-mysql -y##dovecot-mysql是dovecot软件的插件,可以识别mysql

[[email protected] ~]# 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  ##允许铭文认证


[[email protected] ~]# vim /etc/dovecot/conf.d/10-auth.conf
123 !include auth-sql.conf.ext ##开启mysql认证方式


#生成dovecot读取mysql的配置
[[email protected] ~]# cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext


[[email protected] ~]# 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'##查询邮件内容


[[email protected] ~]# 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


[[email protected] ~]# systemctl restart dovecot




【测试】


[[email protected] ~]# 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 [email protected]
+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到的地址是空壳的))

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

mail,postfix,postpix+mariadb,dovecot,dovecot+mariadb,postfix空壳邮件

[[email protected] ~]# vim /etc/postfix/main.cf 
 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


[[email protected] ~]# systemctl restart postfix




测试:
[[email protected] ~]# mail root
[[email protected] ~]# mail
[[email protected] ~]# mail























相关文章: