且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

postfix服务

更新时间:2022-09-13 15:50:07

   **做本次实验之前要配置好两台测试机的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服务

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



postfix服务

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

 


postfix服务

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

 *另一台主机做相同配置

  测试

   westos主机向qq主机发送

postfix服务

  mailq    ##查看邮件队列

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

postfix服务

   qq主机向westos主机发送

postfix服务

postfix服务

 


  3.邮件别名和群发

   vim /etc/aliases

postfix服务


   admin:            root    ##别名

   别名:            真名

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

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

   vim /etc/postfix/moreuser

postfix服务

   postalias /etc/aliases   ##创建文件

   systemctl restart postfix

postfix服务

   测试

    *别名

postfix服务

postfix服务

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

   *群发

postfix服务

postfix服务

postfix服务

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

  

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

   telnet 172.25.254.174 25

postfix服务

postfix服务


   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服务测试


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



 5.限制客户端发送

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

postfix服务

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

postfix服务

  *vim /etc/postfix/access

postfix服务

   172.25.254.74   REJECT

   客户端IP      拒绝访问

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

  *systemctl restart postfix.service

postfix服务

  *测试

postfix服务



  6.限制用户发送

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

postfix服务

postfix服务 

  *vim /etc/postfix/sender

postfix服务

   student@westos.com     REJECT

   用户邮箱            拒绝

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

  *systemctl restart postfix.service 

postfix服务

   测试

postfix服务



  7.限制用户接收

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

postfix服务

postfix服务

 *vim /etc/postfix/recip

postfix服务

  westos@westos.com   REJECT

  用户邮箱         拒绝


  *postmap /etc/postfix/recip

  *systemctl restart postfix.service

postfix服务

 测试

postfix服务

  



  8.出站地址伪装

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

postfix服务

postfix服务


  *vim /etc/postfix/generic

postfix服务


     westos@westos.com  hello@sb.com

    真实名字         虚拟名字

  *postmap /etc/postfix/generic

  *systemctl restart postfix.service

postfix服务 

   测试

postfix服务

postfix服务

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


  9.入战地址转换

  实验之前配置dns

postfix服务


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

postfix服务

  *vim /etc/postfix/virtual

postfix服务

   hello@sb.com   westos@westos.com

    虚拟名字        真实名字

  测试

postfix服务

postfix服务

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



  10.dovecot

  *接收邮件服务器

  *支持协议    协议端口

     pop3     110

     pop3s    995

     imap     143

     imaps    993   

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

postfix服务

 

  *vim /etc/dovecot/dovecot.conf

postfix服务

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

postfix服务

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

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

 

 

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

postfix服务

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

 

 *systemctl restart dovecot.service 

postfix服务

 *在westos用户下

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

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

postfix服务

 *在root用户下

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

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

postfix服务

  测试

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

postfix服务

postfix服务


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


postfix服务


  11.thunderbird

   * 管理邮件收发软件

   * rpm -ihv thunderbird   ##安装软件 

postfix服务

  * 添加用户

postfix服务

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

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

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

postfix服务

  * 发送邮件

postfix服务

  * 接收邮件

postfix服务

本文转自  red777    51CTO博客,原文链接:http://blog.51cto.com/12314711/1928520