**做本次实验之前要配置好两台测试机的dns


  1.基本知识

   *postfix是通过SMTP(简单邮件传输协议)协议接受和转发邮件的软件

   *端口为25

   *服务日志文件 /var/log/maillog

 

  2.配置

   vim /etc/postfix/main.cf

postfix服务_软件

  

  76 myhostname = www.mail.westos.com  ##设置主机名

  83 mydomain =westos.com    ##设置域名



postfix服务_localhost_02

  99 myorigin = westos.com  ##设置发信源主机名称



postfix服务_localhost_03

  116 inet_interfaces = all   ##25端口开启对外接口,默认只在127.0.0.1上开启

 


postfix服务_接口_04

  164 mydestination = $myhostname, $mydomain, localhost  ##接收邮件结尾字符的指定

 *另一台主机做相同配置

  测试

   westos主机向qq主机发送

postfix服务_localhost_05

  mailq    ##查看邮件队列

  postqueue -f  ##重新处理邮件队列

postfix服务_接口_06

   qq主机向westos主机发送

postfix服务_接口_07

postfix服务_localhost_08

 


  3.邮件别名和群发

   vim /etc/aliases

postfix服务_localhost_09


   admin:            root    ##别名

   别名:            真名

   moreuser:        :include:/etc/postfix/moreuser  ##群发

   别名:            记录群发到的用户文件

   vim /etc/postfix/moreuser

postfix服务_接口_10

   postalias /etc/aliases   ##创建文件

   systemctl restart postfix

postfix服务_软件_11

   测试

    *别名

postfix服务_localhost_12

postfix服务_接口_13

给admin用户发送邮件,root用户收到

   *群发

postfix服务_软件_14

postfix服务_软件_15

postfix服务_软件_16

root用户和student用户都收到邮件

  

  4.通过远程主机测试邮件服务

   telnet 172.25.254.174 25

postfix服务_接口_17

postfix服务_localhost_18


   Trying 172.25.254.174...

   Connected to 172.25.254.174.

   Escape character is '^]'.

   220 www.mail.westos.com ESMTP Postfix

   ehlo hello      ##测试连接是否可用

   250-www.mail.westos.com

   250-PIPELINING

   250-SIZE 10240000

   250-VRFY

   250-ETRN

   250-ENHANCEDSTATUSCODES

   250-8BITMIME

   250 DSN

   mail from:root@westos.com    ##邮件从root@westos主机发出

   250 2.1.0 Ok

   rcpt to:root@qq.com        ##root@qq.com主机接收邮件

   250 2.1.5 Ok

   data                  ##输入邮件内容

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

   sdf

   dfdsfa

   dsaf

   .                 ##结束输入内容并发送邮件

   250 2.0.0 Ok: queued as 49A9E24620D

   quit

   221 2.0.0 Bye

   Connection closed by foreign host.

  postfix服务_软件_19测试


root@qq.com主机接收到邮件



 5.限制客户端发送

   *postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access

postfix服务_接口_20

   配置文件/etc/postfix/main.cf会加入如下内容

postfix服务_接口_21

  *vim /etc/postfix/access

postfix服务_localhost_22

   172.25.254.74   REJECT

   客户端IP      拒绝访问

  *postmap /etc/postfix/access   ##文件加密

  *systemctl restart postfix.service

postfix服务_localhost_23

  *测试

postfix服务_接口_24



  6.限制用户发送

  *postconf -e "smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender"

postfix服务_接口_25

postfix服务_localhost_26 

  *vim /etc/postfix/sender

postfix服务_接口_27

   student@westos.com     REJECT

   用户邮箱            拒绝

  *postmap /etc/postfix/sender   ##文件加密

  *systemctl restart postfix.service 

postfix服务_软件_28

   测试

postfix服务_接口_29



  7.限制用户接收

  *postconf -e "smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recip"

postfix服务_localhost_30

postfix服务_软件_31

 *vim /etc/postfix/recip

postfix服务_接口_32

  westos@westos.com   REJECT

  用户邮箱         拒绝


  *postmap /etc/postfix/recip

  *systemctl restart postfix.service

postfix服务_软件_33

 测试

postfix服务_软件_34

  



  8.出站地址伪装

  *postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

postfix服务_软件_35

postfix服务_localhost_36


  *vim /etc/postfix/generic

postfix服务_接口_37


     westos@westos.com  hello@sb.com

    真实名字         虚拟名字

  *postmap /etc/postfix/generic

  *systemctl restart postfix.service

postfix服务_localhost_38 

   测试

postfix服务_接口_39

postfix服务_接口_40

  westsos@westos.com发出的邮件,root@qq.com收到为hello@sb.com发出的


  9.入战地址转换

  实验之前配置dns

postfix服务_软件_41


  *postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

postfix服务_接口_42

  *vim /etc/postfix/virtual

postfix服务_接口_43

   hello@sb.com   westos@westos.com

    虚拟名字        真实名字

  测试

postfix服务_localhost_44

postfix服务_接口_45

发送给hello@sb.com的邮件,westos@westos.com收到



  10.dovecot

  *接收邮件服务器

  *支持协议    协议端口

     pop3     110

     pop3s    995

     imap     143

     imaps    993   

  *yum install dovecot -y   ##安装服务

postfix服务_接口_46

 

  *vim /etc/dovecot/dovecot.conf

postfix服务_软件_47

 24 protocols = imap pop3 lmtp   ##加密协议是imap pop3 lmtp

postfix服务_软件_48

 48 login_trusted_networks = 0.0.0.0/0  ##允许任何ip连接

 49 disable_plaintext_auth = no  ##允许明文登陆

 

 

 *vim /etc/dovecot/conf.d/10-mail.conf

postfix服务_接口_49

 30 mail_location = mbox:~/mail:INBOX=/var/mail/%u   ##指定查看的用户文件 %u表示用户

 

 *systemctl restart dovecot.service 

postfix服务_localhost_50

 *在westos用户下

  [westos@www ~]$ mkdir mail/.imap -p    ##建立邮件目录

  [westos@www ~]$ touch mail/.imap/INBOX  ##建立查看的邮件文件位置

postfix服务_localhost_51

 *在root用户下

  [root@www Desktop]# mkdir /etc/skel/mail/.imap -p  ##自动建立邮件目录

  [root@www Desktop]# touch /etc/skel/mail/.imap/INBOX  ##自动建立查看的邮件文件位置

postfix服务_软件_52

  测试

   mutt -f pop://westos@172.25.254.174    ##pop表示协议

postfix服务_软件_53

postfix服务_localhost_54


*选择O,然后输入westos用户密码,就可以查看172.25.254.174主机westos用户的邮件


postfix服务_软件_55


  11.thunderbird

   * 管理邮件收发软件

   * rpm -ihv thunderbird   ##安装软件 

postfix服务_localhost_56

  * 添加用户

postfix服务_接口_57

    pop3  SMTP     ##文件传输和接收协议 

    110 25        ##发送端口和接收端口

  * 输入密码后,可以查看邮件

postfix服务_软件_58

  * 发送邮件

postfix服务_软件_59

  * 接收邮件

postfix服务_软件_60