zoukankan      html  css  js  c++  java
  • Linux下Postfix的配置和使用

    Postfix为何物,详见:http://zh.wikipedia.org/wiki/Postfix

    0.关于Postfix

    postfix的产生是为了替代传统的sendmail.相较于sendmail,postfix在速度。性能和稳定性上都更胜一筹。如今眼下许多的主流邮件服务事实上都在採用postfix. 当我们须要一个轻量级的的邮件server是,postfix不失为一种选择。

    1. postfix是免费的:
        postfix想要作用的范围是广大的Internet用户。试图影响大多数的Internet上的电子邮件系统,因此它是免费的。
    2. 更快:
        postfix在性能上大约比sendmail快三倍。一部执行postfix的台式PC每天能够收发上百万封邮件。
    3. 兼容性好:
        postfix是sendmail兼容的,从而使sendmail用户能够非常方便地迁移到postfix。Postfix支持/var[/spool]/mail、/etc/aliases、 NIS、和 ~/.forward 文件。
       4. 更健壮:
    postfix被设计成在重负荷之下仍然能够正常工作。当系统执行超出了可用的内存或磁盘空间时,postfix会自己主动降低执行进程的数目。当处理的邮件数目增长时,postfix执行的进程不会跟着添加。
    5. 更灵活:
    postfix是由超过一打的小程序组成的,每一个程序完毕特定的功能。

    你能够
    通过配置文件设置每一个程序的执行參数。


       6. 安全性
    postfix具有多层防御结构,能够有效地抵御恶意入侵者。如大多数的postfix程序能够执行在较低的权限之下,不能够通过网络訪问安全性相关的本地投递程序等等。

    以下来介绍linux上怎样搭建和配置postfix服务:


    1.关掉sendmail相关的全部服务,最好是直接卸载sendmail.

    # service sendmail stop
    # chkconfig sendmail off

    #rpm -qa | grep sendmail | xargs rpm -e


    2.安装postfix.

    redhat6.0以上版本号应该是默认集成了postfix服务的,假如没有安装的话,能够手动安装。

    rpm -qa | grep postifx (查看是否安装)

    yum install postfix


    3.安装完毕后。改动配置文件:/etc/postfix/main.cfg


    vi /etc/postfix/main.cf


    myhostname = sample.test.com  ← 设置系统的主机名


    mydomain = test.com  ← 设置域名(我们将让此处设置将成为E-mail地址“@”后面的部分)


    myorigin = $mydomain  ← 将发信地址“@”后面的部分设置为域名(非系统主机名)


    inet_interfaces = all  ← 接受来自全部网络的请求


    mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ← 指定发给本地邮件的域名


    home_mailbox = Maildir/  ← 指定用户邮箱文件夹


    <保存退出。>


    4.为本机加入DNS server.

    为什DNS Server?由于在邮件发送过程中。须要把邮件地址的domain地址转化成IP地址,再去发送给相应的收件人,这里涉及到DNS中的A记录和MX记录相关的知识,不熟悉的同学能够google或者百度 脑补一下 :-)


    怎样加入DNS server呢,DNS server去哪里寻找?

    vim /etc/resolv.conf 

    加入例如以下行:

    nameserver 8.8.8.8

    nameserver 8.8.4.4


    上面用的8.8.8.8/8.8.4.4是Google Free DNS server,当然还有非常多免费的DNS server供大家使用,能够google一下:-)


    5.測试一下邮件是否可以发送成功:

    命令行输入$: > echo "Mail Content" | mail -s "Mail Subject" xxxx@xxx.com

    Note:if you see below warings after you run above command.

    send-mail: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
    send-mail: warning: inet_protocols: configuring for IPv4 support only
    postdrop: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol
    postdrop: warning: inet_protocols: configuring for IPv4 support only

    that means you don't have IPv6 configured in your OS's network stack, but your mailer (presumably postfix) is configured to use IPv6. Since there is no IPv6 for your mailer to use, it's warning you that it's only going to use IPv4.

     

    To disable the waring messsage, go to /etc/postfix/main.cf and change from:

    inet_protocols = all
    

    to:

    inet_protocols = ipv4
    

    This will only use ipv4 and the warning message will go away.

    You will have to issue a stop and start for postfix to register the change. 

    service postfix restart


    6.查看log,确认邮件发送状态:

    Postfix邮件的log位置是:/var/log/maillog

    发送成功的话。会返回250和OK,也能够去自己的邮件client查收。


    一切OK的话,那Postfix mail service应该就搭建成功了。


    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

    另外一些实用的postfix维护命令。一遍日常的检測和维护:

    mailq :会列出当前在postfix发送队列中的全部邮件

    postsuper -d ALL:删除当前等待发送队列的全部邮件,包含发送失败的退信

    当然还有非常多,就不一一列举了,大家能够网上搜索扩展。Good Luck!


    7.Update Mail From sender

    echo "do-not-reply@example.com   root@example.com" >> /etc/postfix/generic 
    echo "smtp_generic_maps = hash:/etc/postfix/generic" >>/etc/postfix/main.cf 
    postmap /etc/postfix/generic
    service postfix restart

  • 相关阅读:
    论文才考文献批量修改上角标
    Java开发工具打包下载
    navcat导入mdf文件教程
    net::ERR_INCOMPLETE_CHUNKED_ENCODING
    springboot利用AbstractRoutingDataSource实现动态切换数据源
    springboot利用ConfigurationProperties注解配置数据源无法读取配置信息
    with opne()
    专职DBA-基于Dcoker环境初始化三台虚拟机
    因为下游MySQL的sql_mode设置与上游TiDB的sql_mode不一样,导致drainer同步状态下线。
    Mysql语句
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5342619.html
Copyright © 2011-2022 走看看