码迷,mamicode.com
首页 > 其他好文 > 详细

西部开源学习笔记BOOK3《unit 4.SMTP》

时间:2016-12-09 20:19:42      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:linux学习笔记

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

########## unit4.SMTP ##########

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

 

###########1.实验环境搭建############

desktop172.25.254.119

hostnamemaillinux.linux.com

dns-server:172.25.254.219

 

server172.25.254.219

hostnamemailwestos.westos.com

dns-server:172.25.254.219

 

#########2.必要软件的安装#########

[root@mailwestos ~]# yum install bind -y

 

 

#########3.DNS的配置########

server端:

[root@mailwestos ~]# vim /etc/resolv.conf

  2 domain westos.com

  3 search westos.com linux.com

  4 nameserver 172.25.254.219

 

[root@mailwestos ~]# vim /etc/named.conf

 11 //      listen-on port 53 { 127.0.0.1; };\

 12 //      listen-on-v6 port 53 { ::1; };|-->这三行注释掉

 17 //      allow-query     { localhost; };/

 32         dnssec-validation no;##关闭dns安全认证

[root@mailwestos ~]# vim /etc/named.rfc1912.zones

 25 zone "linux.com" IN {

 26         type master;

 27         file "linux.com.zone";

 28         allow-update { none; };

 29 };

 30

 31 zone "westos.com" IN {

 32         type master;

 33         file "westos.com.zone";

 34         allow-update { none; };

 35 };

[root@mailwestos ~]# cd /var/named/

[root@mailwestos named]# cp -p named.localhost westos.com.zone

[root@mailwestos named]# cp -p named.localhost linux.com.zone

[root@mailwestos named]# vim westos.com.zone

  1 $TTL 1D

  2 @       IN SOA  dns.westos.com. root.westos.com. (

  3                                         0       ; serial

  4                                         1D      ; refresh

  5                                         1H      ; retry

  6                                         1W      ; expire

  7                                         3H )    ; minimum

  8                 NS      dns.westos.com.

  9 dns             A       172.25.254.219

 10 westos.com.     MX 1    172.25.254.219.

[root@mailwestos named]# vim linux.com.zone

  1 $TTL 1D

  2 @       IN SOA  dns.linux.com root.linux.com. (

  3                                         0       ; serial

  4                                         1D      ; refresh

  5                                         1H      ; retry

  6                                         1W      ; expire

  7                                         3H )    ; minimum

  8                 NS      dns.linux.com.

  9 dns             A       172.25.254.219

 10 linux.com.      MX 1    172.25.254.119.

##注意:两条MX记录分别对应两个不同的域名和主机ip

[root@mailwestos named]# systemctl start named##启动服务

[root@mailwestos named]# firewall-cmd --permanent --add-service=dns##防火墙允许dns服务

success

[root@mailwestos named]# firewall-cmd --reload ##重启防火墙后生效

success

 

 

desktop端:

[root@maillinux ~]# vim /etc/resolv.conf

domain linux.com

search linux.com westos.com

nameserver 172.25.254.219

 

 

 

测试:

server端:

[root@mailwestos named]# dig -t MX westos.com

;; ANSWER SECTION:

westos.com.86400INMX1 172.25.254.219.

[root@mailwestos named]# dig -t MX linux.com

;; ANSWER SECTION:

linux.com.86400INMX1 172.25.254.119.

 

desktop端:

[root@maillinux ~]# dig -t MX westos.com

;; ANSWER SECTION:

westos.com.86400INMX1 172.25.254.219.

[root@maillinux ~]# dig -t MX linux.com

;; ANSWER SECTION:

linux.com.86400INMX1 172.25.254.119.

 

 

 

#########3.SMTP服务基础配置#########

server端:

[root@mailwestos named]# netstat -antple | grep 25##查看SMTP服务的端口是否开启

tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      25         51218      3223/named          

tcp        0      0 172.25.254.219:53       0.0.0.0:*               LISTEN      25         51215      3223/named          

tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      25         51213      3223/named          

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          20925      1262/sshd           

tcp        0      0 172.25.254.219:22       172.25.254.19:55336     ESTABLISHED 0          25114      1588/sshd: root@pts

tcp6       0      0 ::1:953                 :::*                    LISTEN      25         51219      3223/named          

tcp6       0      0 :::25                   :::*                    LISTEN      0          21229      1386/master         

tcp6       0      0 :::111                  :::*                    LISTEN      0          20425      1276/rpcbind        

##经查看并为开启SMTP服务的端口

 

[root@mailwestos named]# vim /etc/postfix/main.cf ##配置SMTP主配置文件

 75 myhostname = mailwestos.westos.com##设置自己的主机名

 83 mydomain = westos.com##设置自己的域名

 99 myorigin = $mydomain##设置源=(自己的域名)

113 inet_interfaces = all##开放所有ip上的25端口

116 #inet_interfaces = localhost##将这一行注释掉(否则会影响第113)

164 mydestination = $myhostname, $mydomain, localhost##只处理发给(自己的主机名|域名|localhost)的邮件

[root@mailwestos named]# systemctl restart postfix.service##重启服务后生效

 

测试:

server端:

[root@mailwestos named]# mail root@westos.com##server给自己发mail

Subject: 123

ewqe

dawd

dawd

.

EOT

[root@mailwestos named]# mail##查看所有邮件

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 1 message 1 unread

>U  1 root                  Tue Nov 29 10:11  21/576   "123"

&

##发送成功。(此时是219主机给自己发mail,因为119主机上并未配置smtp,所以219现在无法给119mail)

 或:

[root@mailwestos ~]# mail -u root##查看发给rootmail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/root": 1 message 1 unread

>U  1 root                  Tue Nov 29 10:11  21/576   

&

 

 

==================注意=======================

上面的测试是servermailserver端,不需要关闭防火墙。

serverdesktop之间相互发送mail的时候,要将双方的防火墙关闭,否则会发送失败。

============================================

 

补充:

1.mail发送失败时,会保存下来。

[root@mailwestos named]# mail root@linux.com##发给linux.com,但linux.com并未配置smtp

Subject: tbr

qeqwdwwa

dawda

dawdaw

.

EOT

[root@mailwestos named]# mailq##查看待寄mail的清单及其相关信息

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------

D2ABE24620B      447 Tue Nov 29 10:21:22  root@westos.com

              (connect to 172.25.254.119[172.25.254.119]:25: No route to host)

                                         root@linux.com

 

-- 0 Kbytes in 1 Request.

[root@mailwestos named]# postqueue -p##查看寄存队列内容

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------

1830C246219      443 Fri Dec  2 02:25:05  root@westos.com

(Host or domain name not found. Name service error for name=linux.com type=MX: Host not found, try again)

                                         root@linux.com

 

-- 0 Kbytes in 1 Request.

[root@mailwestos named]# postqueue -f##将待寄存队列的mail再发送一遍

[root@mailwestos named]# postsuper -d D2ABE24620B##删除发送失败的mail,‘D2ABE24620B为该条mail的标示

postsuper: D2ABE24620B: removed

postsuper: Deleted: 1 message

[root@mailwestos named]# postsuper -dALL##删除队列的所有寄存mail

 

 

[root@mailwestos named]# postconf -d##查看默认配置

[root@mailwestos named]# postconf -n##查看当前的配置

 

[root@mailwestos named]# postconf -e "inet_interface=localhost"

[root@mailwestos named]# postconf -d | grep inet

inet_interfaces = all

inet_protocols = all

local_header_rewrite_clients = permit_inet_interfaces

[root@mailwestos named]# vim /etc/postfix/main.cf

 

[root@mailwestos named]# ll /usr/sbin/sendmail

lrwxrwxrwx. 1 root root 21 5月   6 2014 /usr/sbin/sendmail -> /etc/alternatives/mta

[root@mailwestos named]# ll /etc/alternatives/mta

lrwxrwxrwx. 1 root root 26 5月   6 2014 /etc/alternatives/mta -> /usr/sbin/sendmail.postfix

 

#########4.主机之间发送mail##########

server端:

[root@mailwestos named]# systemctl stop firewalld.service##关闭防火墙

[root@mailwestos named]# scp /etc/postfix/main.cf root@172.25.254.119:/etc/postfix/main.cf

 

desktop端:

[root@maillinux named]# vim /etc/postfix/main.cf ##配置SMTP主配置文件

:%s/westos/linux/g##将全局的westos换为linuxok

[root@maillinux named]# systemctl restart postfix.service##重启服务后生效

[root@mailwestos named]# systemctl stop firewalld.service##关闭防火墙

 

 

测试:

desktop--->server

[root@maillinux ~]# mail root@westos.com

Subject: test1

dawdaw

dawda

wdaw

da

w

.

EOT

 

[root@mailwestos named]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 1 message 1 new

>N  1 root                  Fri Dec  2 08:34  25/755   

& 1

Message  1:

From root@linux.com  Fri Dec  2 08:34:35 2016

Return-Path: <root@linux.com>

X-Original-To: root@westos.com

Delivered-To: root@westos.com

Date: Fri, 02 Dec 2016 08:33:45 -0500

To: root@westos.com

Subject: test1

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: root@linux.com (root)

Status: R

 

dawdaw

dawda

wdaw

da

w

 

&

 

 

server--->server:

[root@mailwestos named]# mail root@linux.com

Subject: test2

wqqdwq

dawdwfda

dawdaw

.

EOT

 

[root@maillinux ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 1 message 1 new

>N  1 root                  Fri Dec  2 08:39  23/761   

& 1

Message  1:

From 173209146@qq.com  Fri Dec  2 08:39:06 2016

Return-Path: <173209146@qq.com>

X-Original-To: root@linux.com

Delivered-To: root@linux.com

Date: Fri, 02 Dec 2016 08:39:06 -0500

To: root@linux.com

Subject: test2

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: 173209146@qq.com (root)

Status: R

 

wqqdwq

dawdwfda

dawdaw

 

&

 

 

 

#########4.虚拟邮件帐号#########

这个虚拟帐号名可以是系统中存在的帐号,也可以是不存在的。

 

正常情况下:

server端存在student用户,desktopserverstudent用户发送邮件恶的情况如下:

[root@maillinux ~]# mail student@westos.com

Subject: test3

awdwqe

dwqdq

.

EOT

[root@mailwestos named]# mail -u student##student用户收到mail,而不是root

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/student": 1 message

>   1 root                  Tue Dec  6 01:43  23/805   "student"

&

 

 

修改了虚拟用户之后:

server端:

[root@mailwestos named]# vim /etc/aliases

 97 admin:          root

 98 student:        root

 

[root@mailwestos named]# postalias /etc/aliases##加密(hash)生成db文件

[root@mailwestos named]# ll /etc/aliases*

-rw-r--r--. 1 root root  1576 12月  2 09:30 /etc/aliases

-rw-r--r--. 1 root root 12288 12月  2 09:08 /etc/aliases.db##生成了该文件(系统最后读的是这个文件)

[root@mailwestos named]# systemctl restart postfix.service ##重启服务后生效

 

 

测试:

desktop端:

[root@maillinux ~]# mail admin@westos.com

Subject: test3

adwdq

dawdawd

dadawd

.

EOT

[root@maillinux ~]# mail student@westos.com

Subject: test4

qweqwd

dqwdzcfad

dawdawdwa

dqwdq

.

EOT

 

server端:

[root@mailwestos named]# mail -u root##发给adminstudentmail其实是root接收了

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 3 messages 1 unread

    1 root                  Fri Dec  2 08:34  26/766   

    2 root                  Fri Dec  2 09:06  24/768 ##这个是admin(实际收件人为root)  

>U  3 root                  Fri Dec  2 09:09  25/787   ##这个是student(实际收件人为root

&

 

 

##########5.邮件群发###########

server端:

[root@mailwestos named]# vim /etc/aliases

 97 admin:          root##删除此行

 98 student:        root##删除此行

 99 more:           :include:/etc/moreusers##指定群发的用户文件

=========================

 99 more:           adminstudent

[root@mailwestos named]# postalias /etc/aliases##重新生成db加密文件

[root@mailwestos named]# systemctl restart postfix.service ##重启服务后生效

[root@mailwestos named]# vim /etc/moreusers

  1 admin

  2 student

 

创建amdinstudent用户:

[root@mailwestos named]# useradd admin

[root@mailwestos named]# useradd student

[root@mailwestos named]# id admin

uid=1001(admin) gid=1001(admin) groups=1001(admin)

[root@mailwestos named]# id student

uid=1000(student) gid=1000(student) groups=1000(student)

 

测试:

desktop端:

[root@maillinux ~]# mail more@westos.com

Subject: 123

adawdwq

dwadawd

dawdaw

.

EOT

 

server端:

[root@mailwestos named]# mail -u student

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/student": 2 messages 1 new

>N  2 root                  Tue Dec  6 02:02  25/912   "123"

[root@mailwestos named]# mail -u admin

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/mail/admin": 1 message 1 new

>N  1 root                  Tue Dec  6 02:02  25/910   "123"

##两个用户都收到了mail

 

 

#########6.mail地址的别名########

desktop端:

[root@maillinux postfix]# ls

access     generic        main.cf    relocated  virtual

canonical  header_checks  master.cf  transport  

[root@maillinux postfix]# vim virtual

295 173209146@qq.com root@westos.com

[root@maillinux postfix]# postmap virtual##生成virtual.db加密文件

[root@maillinux postfix]# ls

access     generic        main.cf    relocated  virtual

canonical  header_checks  master.cf  transport  virtual.db

[root@maillinux postfix]# postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"##/etc/postfix/main.cf主配置文件添加该条参数

[root@maillinux postfix]# systemctl restart postfix.service

 

 

测试:

desktop端:

[root@maillinux postfix]# mail 173209146@qq.com

Subject: hehehe

dfqwfqwf

qwfwwqfqwf

.

EOT

 

server端:

[root@mailwestos postfix]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 3 messages 1 new

>N  1 root                  Tue Dec  6 03:05  22/753   "hehehe"

&

 

 

 

#########7.出站地址伪装##########

[root@mailwestos named]# cd /etc/postfix/

[root@mailwestos postfix]# vim generic

240 root@westos.com 173209146@qq.com     ##前面的是原本的域名,后面的是伪装的域名

[root@mailwestos postfix]# ls

access     generic        main.cf    relocated  virtual

canonical  header_checks  master.cf  transport

[root@mailwestos postfix]# postmap generic##生成generic.db加密文件

[root@mailwestos postfix]# ls

access     generic.db     master.cf  virtual

canonical  header_checks  relocated  

generic    main.cf        transport

[root@mailwestos postfix]# postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"##/etc/postfix/main.cf主配置文件添加该条参数

[root@mailwestos postfix]# systemctl restart postfix.service

 

 

 

测试:

server端:

[root@mailwestos postfix]# mail root@linux.com

Subject: tbr

qweqw

dada

w

.

EOT

 

desktop端:

[root@maillinux ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 1 message 1 new

>N  1 root                  Sun Nov 27 03:46  23/749   "tbr"

& 1

Message  1:

From 173209146@qq.com  Sun Nov 27 03:46:51 2016

Return-Path: <173209146@qq.com>

X-Original-To: root@linux.com

Delivered-To: root@linux.com

Date: Sun, 27 Nov 2016 03:46:50 -0500

To: root@linux.com

Subject: tbr

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: 173209146@qq.com (root)

Status: R

 

qweqw

dada

w

 

&

 

 

 

###########8.通过telnet远程登陆发送邮件############

##真实主机上安装Telnet软件(真实主机ip172.25.254.19)

[root@foundation19 Software]# yum install telnet -y

 

[root@foundation19 Software]# telnet 172.25.254.219 25##通过25端口连接

Trying 172.25.254.219...

Connected to 172.25.254.219.

Escape character is ‘^]‘.

220 mailwestos.westos.com ESMTP Postfix

 

500 5.5.2 Error: bad syntax

ehlo hello##显示如下,则登陆成功

250-mailwestos.westos.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:root@linux.com##mail由发送方

250 2.1.0 Ok

rcpt to:root@westos.com##mail的接受方

250 2.1.5 Ok

data##输入data之后下面写正文

354 End data with <CR><LF>.<CR><LF>

dafadada

adad

dawdad

adad

.

250 2.0.0 Ok: queued as 4541524620D

quit ##退出

Connection closed by foreign host.

[root@foundation19 Software]#

 

 

 

###########9.根据ip来拒绝smtp连接请求##########

##该配置会导致被拒绝的ip主机telnet上邮件服务器之后无法收发邮件(实际是拒绝了smtp连接请求)。注意不要和邮件服务器本地用户的在服务器端直接收发邮件的权限混淆。

[root@mailwestos ~]# cd /etc/postfix/

[root@mailwestos postfix]# vim access

477 172.25.254.19   REJECT##此处填写拒绝的主机ip(本实验是真实主机ip172.25.254.19,注意:477是行号)

[root@mailwestos postfix]# ls

access     generic        main.cf    relocated  virtual

canonical  header_checks  master.cf  transport

[root@mailwestos postfix]# postmap access ##生成.db加密文件

[root@mailwestos postfix]# ls

access     canonical  header_checks  master.cf  transport

access.db  generic    main.cf        relocated  virtual

 

[root@mailwestos postfix]# postconf -d | grep client##通过该命令查询关于mail-serverclient的配置

broken_sasl_auth_clients = no

local_header_rewrite_clients = permit_inet_interfaces

parent_domain_matches_subdomains =

.

.

.

smtpd_client_recipient_rate_limit = 0

smtpd_client_restrictions =##应用这条命令

unknown_client_reject_code = 450

[root@mailwestos postfix]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"

##将该条配置加到主配置文件中,注意这里面的access其实指的是access.db文件

[root@mailwestos postfix]# vim /etc/postfix/main.cf ##检查上条命令是否生效

680 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access

##有此行表示生效了

[root@mailwestos postfix]# systemctl restart postfix.service##重启服务生效

 

 

测试:

真实主机(172.25.254.19):

[root@foundation19 Desktop]# telnet 172.25.254.219 25

Trying 172.25.254.219...

Connected to 172.25.254.219.

Escape character is ‘^]‘.

220 mailwestos.westos.com ESMTP Postfix

ehlo hello##可以成功telnet到服务器端

250-mailwestos.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@linux.com##此时会产生报错,因为clientip被拒绝了

554 5.7.1 <unknown[172.25.254.19]>: Client host rejected: Access denied

 

 

##########10.禁止邮件服务器本地的指定用户发送mail##############

##该配置会导致被远程登陆上邮件服务器无法使用指定的用户进行发件。注意不要和邮件服务器本地用户的在服务器端直接发邮件的权限混淆。

 

注意:在该实验之前先将上一个实验中的部分配置删除,否册影响实验

[root@mailwestos postfix]# vim /etc/postfix/main.cf

680 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access

##删除该行

 

server端:

[root@mailwestos postfix]# vim sender##这个文件在/etc/postfix/下没有,需要自己创建(可以自命名)

westos@westos.com       REJECT##这里要写用户+域名(此处禁止了server端的westos用户发送mail

[root@mailwestos postfix]# postmap sender ##生成.db加密文件

[root@mailwestos postfix]# ls

access     header_checks    mysql-maildir.cf  sender.db

access.db  main.cf          mysql-user.cf     transport

canonical  master.cf        relocated         virtual

generic    mysql-domain.cf  sender

[root@mailwestos postfix]# postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/posfix/sender"

##将该条配置加到主配置文件中,注意这里面的sender其实指的是sender.db文件

[root@mailwestos postfix]# vim /etc/postfix/main.cf ##检查上条命令是否生效

681 smtpd_sender_restrictions = check_sender_access hash:    /etc/posfix/sender

##有此行表示生效了

[root@mailwestos postfix]# systemctl restart postfix.service##重启服务生效

 

[root@mailwestos postfix]# useradd westos##创建westos用户,作为测试用

[westos@mailwestos postfix]$ id westos

uid=1002(westos) gid=1002(westos) groups=1002(westos)

 

 

测试:

真实主机(172.25.254.19):

[root@foundation19 Desktop]# telnet 172.25.254.219 25

Trying 172.25.254.219...

Connected to 172.25.254.219.

Escape character is ‘^]‘.

220 mailwestos.westos.com ESMTP Postfix

mail from:westos@westos.com##注意;此处是用westos用户发送

250 2.1.0 Ok

rcpt to:root@linux.com##无法发送,发送方的地址被拒绝

451 4.3.5 <westos@westos.com>: Sender address rejected: Access denied

 

 

============邮件服务器本地的westos用户还是可以发送的========

server端:

[root@mailwestos postfix]# su - westos

[westos@mailwestos ~]$ mail root@linux.com

Subject: tbr

adwdwq

dawdwad

fawdawd

.

EOT

 

desktop端:

[root@maillinux ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 1 message 1 new

>N  1 westos@westos.com     Sat Dec  3 06:00  23/754   

& 1

 

 

 

#########11.禁止指定用户接收mail###############

[root@mailwestos postfix]# vim recip##这个文件在/etc/postfix/下没有,需要自己创建(可以自命名)

  1 westos@westos.com       REJECT

[root@mailwestos postfix]# postmap recip ##生成.db加密文件

[root@mailwestos postfix]# postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"

##将该条配置加到主配置文件中,注意这里面的sender其实指的是sender.db文件

[root@mailwestos postfix]# systemctl restart postfix.service ##重启服务后生效

 

测试:

真实主机(172.25.254.19

[root@foundation19 Desktop]# telnet 172.25.254.219 25

Trying 172.25.254.219...

Connected to 172.25.254.219.

Escape character is ‘^]‘.

220 mailwestos.westos.com ESMTP Postfix

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

 

 

##########12.dovecotmail##########

server端:

[root@mailwestos ~]# yum install dovecot -y

[root@mailwestos ~]# cd /etc/dovecot/

[root@mailwestos dovecot]# ls

conf.d  dovecot.conf

[root@mailwestos dovecot]# vim dovecot.conf

 24 protocols = imap pop3 lmtp

 46 # for authentication checks). disable_plaintext_auth is     also ignored for

 49 disable_plaintext_auth = no

[root@mailwestos dovecot]# cd conf.d/

[root@mailwestos conf.d]# vim 10-mail.conf

 25 #   mail_location = mbox:~/mail:INBOX=/var/mail/%u

 30 mail_location = mbox:~/mail:INBOX=/var/mail/%n##注意:这里改为%n

[root@mailwestos conf.d]# systemctl start dovecot

[root@mailwestos conf.d]# netstat -antple| grep dovecot

tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      0          59637      3274/doveco        

tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      0          59613      3274/doveco        

tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      0          59611      3274/doveco        

tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      0          59635      3274/doveco        

tcp6       0      0 :::993                  :::*                    LISTEN      0          59638      3274/doveco        

tcp6       0      0 :::995                  :::*                    LISTEN      0          59614      3274/doveco        

tcp6       0      0 :::110                  :::*                    LISTEN      0          59612      3274/doveco        

tcp6       0      0 :::143                  :::*                    LISTEN      0          59636      3274/doveco        

 

[root@mailwestos conf.d]# su - westos

[westos@mailwestos ~]$ mkdir -p mail/.imap/

[westos@mailwestos ~]$ touch mail/.imap/INBOX

 

[westos@mailwestos ~]$ logout

[root@mailwestos conf.d]# cd /etc/skel/

[root@mailwestos skel]# mkdir -p mail/.imap

[root@mailwestos skel]# touch mail/.imap/INBOX

[root@mailwestos ~]# useradd tbr

[root@mailwestos ~]# su - tbr

[tbr@mailwestos ~]$ ls

mail

[tbr@mailwestos ~]$ cd mail/

[tbr@mailwestos mail]$ ls -a

.  ..  .imap

[tbr@mailwestos mail]$ cd .imap/

[tbr@mailwestos .imap]$ ls

INBOX

 

 

 

真实主机端:

[root@foundation19 Desktop]# yum install mutt -y

 

server端:

[root@mailwestos conf.d]# > /var/log/maillog

 

 

 

#########14.thunderbird雷鸟(本地邮件代理)#########

1.安装thunderbird

[root@maillinux mnt]# lftp 172.25.254.250

====/pub/docs/softwareget thunderbird-31.4.0.tar.bz2=====

[[root@maillinux mnt]# ls

thunderbird-31.4.0.tar.bz2

[root@maillinux mnt]# tar jxf thunderbird-31.4.0.tar.bz2

ls

[root@maillinux mnt]# ls

thunderbird  thunderbird-31.4.0.tar.bz2

[root@maillinux mnt]# cd thunderbird/

 

===========以下这部分,是用来将thunderbird需要的的相关软件也找出来并安装==========

[root@maillinux thunderbird]# ./thunderbird

-bash: ./thunderbird: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

[root@maillinux thunderbird]# yum whatprovides /lib/ld-linux.so.2

[root@maillinux thunderbird]# yum isntall glibc-2.17-55.el7.i686 -y

==========================================================================

 

[root@maillinux thunderbird]# ./thunderbird

(process:2668): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0‘ failed

Error: no display specified##直到最后显示为这个:表示图形无法打开

 

[root@maillinux thunderbird]# logout##关闭ssh,并以图形的方式建立ssh连接

Connection to 172.25.254.119 closed.

[root@foundation19 Desktop]# ssh root@172.25.254.119 -X##注意:此处加-X

root@172.25.254.119‘s password:

Last login: Thu Dec  8 02:56:30 2016 from 172.25.254.19

 

2.设置dovecot

[root@mailwestos ~]# vim /etc/dovecot/dovecot.conf

 48 login_trusted_networks = 0.0.0.0/0

[root@mailwestos ~]# systemctl restart dovecot.service

 

3.配置之前创建的westos用户和tbr用户

注意:westos用户有密码,但此时tbr用户没有密码,需要加一个密码

 

[root@maillinux ~]# cd /mnt/

[root@maillinux mnt]# ls

thunderbird  thunderbird-31.4.0.tar.bz2

[root@maillinux mnt]# cd thunderbird/

[root@maillinux thunderbird]# ./thunderbird

 

您的大名:westos

电子邮件地址:westos@westos.com

伺服器主机名称SSL认证

收件:IMAP172.25.254.219143自动侦测

寄件:SMTP172.25.254.21925自动侦测


使用者名称:收件westos寄件:westos


下图为添加tbr用户:

 技术分享

【重新测定】

技术分享

【下载邮件】即可

 技术分享

 技术分享

 

 

###########15.与数据库关联,建立虚拟用户############

指定所有的用户

1.安装软件

server端:

[root@mailwestos ~]# yum install mariadb-server httpd php php-mysql.x86_64 -y

[root@mailwestos ~]# cd /var/www/html/

[root@mailwestos html]# lftp 172.25.254.250

=======/pub/docs/softwareget phpMyAdmin-3.4.0-all-languages.tar.bz2

[root@mailwestos html]# ls

phpMyAdmin-3.4.0-all-languages.tar.bz2

 

 

2.配置MYSQL

server端:

[root@mailwestos html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2

[root@mailwestos html]# ls

phpMyAdmin-3.4.0-all-languages

phpMyAdmin-3.4.0-all-languages.tar.bz2

[root@mailwestos html]# rm -fr phpMyAdmin-3.4.0-all-languages.tar.bz2

[root@mailwestos html]# ls

phpMyAdmin-3.4.0-all-languages

[root@mailwestos html]# mv phpMyAdmin-3.4.0-all-languages myadmin

[root@mailwestos html]# ls

myadmin

[root@mailwestos html]# cd myadmin/

[root@mailwestos myadmin]# cp config.sample.inc.php config.inc.php

[root@mailwestos myadmin]# vim config.inc.php

 17 $cfg[‘blowfish_secret‘] = ‘tbr‘; /* YOU MUST FILL IN THIS FOR     COOKIE AUTH! */

[root@mailwestos myadmin]# vim /etc/hosts

  6 172.25.254.219 mailwestos.westos.com westos.org

[root@mailwestos myadmin]# systemctl start httpd

[root@mailwestos myadmin]# systemctl start mariadb

[root@mailwestos myadmin]# mysql_secure_installation

[root@mailwestos myadmin]# systemctl restart mariadb.service

[root@mailwestos myadmin]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.35-MariaDB MariaDB Server

 

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

 

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

 

MariaDB [(none)]>

 

 

测试:

真实主机(172.25.254.219

http://172.25.254.219/myadmin/

输入【帐号】【密码】

 技术分享

新建数据库:email

 

技术分享

技术分享

技术分享

技术分享

技术分享

技术分享


 

server端:

[root@mailwestos myadmin]# mysql -uroot -p

Enter password:

MariaDB [(none)]> select * from email.vuser

+------------------+----------+------------+-------------------------------+

| username         | password | domain     | maildir                       |

+------------------+----------+------------+-------------------------------+

| admin@westos.org | 123      | westos.org | /home/vmail/westos.org/admin/ |

+------------------+----------+------------+-------------------------------+

1 row in set (0.00 sec)

 

MariaDB [(none)]> CREATE USER postfix@localhost identified by ‘postfix‘;

Query OK, 0 rows affected (0.00 sec)

##创建虚拟用户table的管理用户postfix

MariaDB [(none)]> GRANT SELECT,INSERT,UPDATE on email.* to postfix@localhost;

Query OK, 0 rows affected (0.00 sec)

##发放权限给管理员postfix

MariaDB [(none)]> quit

Bye

 

[root@mailwestos myadmin]# mysql -upostfix -ppostfix

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| email              |

+--------------------+

2 rows in set (0.00 sec)

 

MariaDB [(none)]> SELECT * FROM email.vuser;

+------------------+----------+------------+-------------------------------+

| username         | password | domain     | maildir                       |

+------------------+----------+------------+-------------------------------+

| admin@westos.org | 123      | westos.org | /home/vmail/westos.org/admin/ |

+------------------+----------+------------+-------------------------------+

1 row in set (0.00 sec)

MariaDB [(none)]> quit

Bye

 

[root@mailwestos myadmin]# cd /etc/postfix/

[root@mailwestos postfix]# vim mysql-user.cf

  1 hosts = localhost

  2 user = postfix

  3 password = postfix

  4 dbname = email

  5 table = vuser

  6 select_field = username

  7 where_field = username

[root@mailwestos postfix]# postmap -q "admin@westos.org" mysql:/etc/postfix/mysql-user.cf

[root@mailwestos postfix]# postmap -q "admin@westos.org" mysql:/etc/postfix/mysql-user.cf##再次执行后有如下显示则生效

admin@westos.org

[root@mailwestos postfix]# postmap -q "tbr@westos.org" mysql:/etc/postfix/mysql-user.cf

[root@mailwestos postfix]# postmap -q "tbr@westos.org" mysql:/etc/postfix/mysql-user.cf

tbr@westos.org

[root@mailwestos postfix]# cp -p mysql-user.cf mysql-domain.cf

[root@mailwestos postfix]# cp -p mysql-user.cf mysql-maildir.cf

[root@mailwestos postfix]# vim mysql-domain.cf

  1 hosts = localhost

  2 user = postfix

  3 password = postfix

  4 dbname = email

  5 table = vuser

  6 select_field = domain

  7 where_field = domain

[root@mailwestos postfix]# vim mysql-maildir.cf

  1 hosts = localhost

  2 user = postfix

  3 password = postfix

  4 dbname = email

  5 table = vuser

  6 select_field = maildir

  7 where_field = username

[root@mailwestos postfix]# groupadd -g 666 vmail

[root@mailwestos postfix]# useradd -u 666 -g 666 vmail -s /sbin/nologin

[root@mailwestos postfix]# postconf -e "virtual_gid_maps = static:666"

[root@mailwestos postfix]# postconf -e "virtual_uid_maps = static:666"

[root@mailwestos postfix]# postconf -e "virual_mailbox_base = /home/vmail"

 

[root@mailwestos postfix]# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-user.cf"

[root@mailwestos postfix]# ll /etc/postfix/mysql-user.cf

-rw-r--r--. 1 root root 128 12月  8 07:49 /etc/postfix/mysql-user.cf

 

[root@mailwestos postfix]# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domain.cf"

[root@mailwestos postfix]# ll /etc/postfix/mysql-domain.cf

-rw-r--r--. 1 root root 124 12月  8 08:03 /etc/postfix/mysql-domain.cf

 

[root@mailwestos postfix]# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-maildir.cf"

[root@mailwestos postfix]# ll /etc/postfix/mysql-maildir.cf

-rw-r--r--. 1 root root 127 12月  8 08:04 /etc/postfix/mysql-maildir.cf

 

[root@mailwestos vmail]# systemctl restart postfix.service

 

 

 

测试:

server端:

[root@mailwestos vmail]# mail admin@westos.org

Subject: test1

afwfqfq

qwfqwfwqdfq

.

EOT

[root@mailwestos vmail]# ls

mail  westos.org

[root@mailwestos vmail]# cd westos.org/

[root@mailwestos westos.org]# ls

admin

[root@mailwestos westos.org]# cd admin/

[root@mailwestos admin]# ls

cur  new  tmp

[root@mailwestos admin]# cat new/1481204095.Vfd01I271795M137319.mailwestos.westos.com

Return-Path: <root@westos.com>

X-Original-To: admin@westos.org

Delivered-To: admin@westos.org

Received: by mailwestos.westos.com (Postfix, from userid 0)

id 17E9E271786; Thu,  8 Dec 2016 08:34:54 -0500 (EST)

Date: Thu, 08 Dec 2016 08:34:54 -0500

To: admin@westos.org

Subject: test1

User-Agent: Heirloom mailx 12.5 7/5/10

MIME-Version: 1.0

Content-Type: text/plain; charset=us-ascii

Content-Transfer-Encoding: 7bit

Message-Id: <20161208133455.17E9E271786@mailwestos.westos.com>

From: root@westos.com (root)

 

afwfqfq

qwfqwfwqdfq

 

 

 

 

############16.postfix+mariadb(MYSQL)+thunderbird##############

[root@mailwestos admin]# cd /etc/dovecot/conf.d/

[root@mailwestos conf.d]# vim 10-auth.conf

123 !include auth-sql.conf.ext##将此行注释取消掉

[root@mailwestos conf.d]# cd /usr/share/doc/dovecot-2.2.10/example-config/

[root@mailwestos example-config]# ls

conf.d        dovecot-dict-auth.conf.ext  dovecot-ldap.conf.ext

dovecot.conf  dovecot-dict-sql.conf.ext   dovecot-sql.conf.ext

[root@mailwestos example-config]# cp dovecot-sql.conf.ext /etc/dovecot/

[root@mailwestos example-config]# cd /etc/dovecot/

[root@mailwestos dovecot]# 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 vuser WHERE username = ‘%u‘ AND domain = ‘%d‘

125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM vuser WHERE username = ‘%u‘

 

[root@mailwestos dovecot]# cd conf.d/

[root@mailwestos conf.d]# vim 10-mail.conf

 30 mail_location = maildir:/home/vmail/%d/%n

168 first_valid_uid = 666

175 first_valid_gid = 666

[root@mailwestos conf.d]# systemctl restart dovecot.service


西部开源学习笔记BOOK3《unit 4.SMTP》

标签:linux学习笔记

原文地址:http://10664148.blog.51cto.com/10654148/1881130

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!