美文网首页
Centos 配置postfix 服务器

Centos 配置postfix 服务器

作者: 二棉酷 | 来源:发表于2018-12-17 15:23 被阅读0次

    1.postfix的安装:
    卸载sendmail
    # yum remove sendmail
    卸载postfix
    # yum remove postfix
    重新安装postfix
    # yum install postfix
    因为卸载postfix的时候系统定时服务也被卸载核心服务也同步安装
    # yum install crontabs
    提供smtp的虚拟账户和密码服务
    # yum install cyrus-sasl*
    当前mta查看
    # alternatives --display mta
    如果是 当前“最佳”版本是 /usr/sbin/sendmail.postfix。 就不需要修改,
    如果不是,设置mta
    # /usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix
    再次查看mta
    # alternatives --display mta
    设置postfix开机启动
    # chkconfig postfix on

    2.postfix配置并启用smtp
    编辑postfix配置文件

    vim /etc/postfix/main.cf

    找到如下配置项酌情修改:
    postfix主机名
    myhostname = mail.caefcs.com
    域名
    mydomain = caefcs.com
    本机postfix的邮箱域名后最 此项默认值使用myhostname
    此处使用了前项mydomain 也就是说本机postfix邮箱后缀为:@caefcs.com
    myorigin = $mydomain
    指定postfix系统监听的网络接口 此处必须是localhost或127.0.0.1或内网ip
    若注释或填入公网ip 服务器的25端口将对公网开放
    默认值为all 即监听所有网络接口
    此项指定localhost后 本机postfix就只能发邮件不能接收邮件
    inet_interfaces = all
    网络协议 ipv6、ipv4或者all
    inet_protocols = all
    指定postfix接收邮件时收件人的域名,换句话说,也就是你的postfix系统要接收什么样的邮件。
    此项配置中myhostname表示postfix接受@myhostname为后缀的邮箱的邮件,逗号分割支持指多项
    此项默认值使用myhostname
    mydestination = $myhostname,localhost.$mydomain,localhost,$mydomain
    此项制定接收邮件的规则 可以是hash文件 此项对本次配置无意义 可以直接注释
    local_recipient_maps =
    指定你所在的网络的网络地址
    最好加上你要在第三方上使用的服务器,不加的话可能无法使用在第三方上面
    请依据实际情况修改
    mynetworks =127.0.0.0/8, ****
    指定MUA通过smtp连接postfix时返回的header头信息
    原始配置附带有postfix版本号 去掉即可,此项酌情处理
    smtpd_banner = $myhostname ESMTP $mail_name

    下面的部分直接粘在文件结尾:

    指定postfix兼容MUA使用不规则的smtp协议--主要针对老版本的outlook 此项对于本次配置无意义

    broken_sasl_auth_clients = yes

    指定可以向postfix发起SMTP连接的客户端的主机名或ip地址

    此处permit_sasl_authenticated意思是允许通过sasl认证(也就是smtp链接时通过了账号、密码效验的用户)的所有用户

    smtpd_client_restrictions = permit_sasl_authenticated

    发件人在执行RCPT TO命令时提供的地址进行限制规则 此处照搬复制即可

    smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

    指定postfix使用sasl验证 通俗的将就是启用smtp并要求进行账号、密码效验

    smtpd_sasl_auth_enable = yes

    指定SMTP认证的本地域名 本次配置可以使用 smtpd_sasl_local_domain = '' 或干脆注释掉 默认为空

    smtpd_sasl_local_domain = $mydomain

    取消smtp的匿名登录 此项默认值为noanonymous smtp若能匿名登录危害非常大 此项请务必指定为noanonymous

    smtpd_sasl_security_options = noanonymous

    指定通过postfix发送邮件的体积大小 此处表示5M

    message_size_limit = 5242880

    3.修改主机名称
    查看主机名称
    # hostname
    修改主机名称
    # vim /etc/sysconfig/network
    配置为
    myhostname=mail.caefcs.com
    查看防火墙状态
    service iptables status
    关闭防火墙
    chkconfig iptables off
    重启
    # shutdown -r now

    4.sasldb2建立smtp用户和密码
    # vim /etc/sasl2/smtpd.conf
    编辑如下:
    pwcheck_method: auxprop
    auxprop_plugin: sasldb
    mech_list: plain login CRAM-MD5 DIGEST-MD5

    5.创建smtp账号
    # saslpasswd2 -c -u `postconf -h mydomain` charm
    回车会要求输入密码,连续两次
    表示创建charm@$mydomain的邮箱账号(也是smtp的账号)和密码
    本例就是创建charm@caefcs.com账号和密码
    此处注意的是smtp登录用的账号并不是单纯的用户名,而是整个邮箱地址字符串
    假设此处设置的smtp账号charm@caefcs.com密码为charm,下方测试时要用到

    查看sasldb2的用户和密码
    # sasldblistusers2
    此命令进用户查看sasldb的用户情况
    此命令回车后会输出诸如这样的内容:charm@caefcs.com: userPassword
    # service postfix restart
    每次添加smtp用户完毕之后需重启postfix或reload

    6.测试postfix配置文件并启动postfix
    # service postfix check
    没有问题的话会返回着色[确定]字样
    更改sasldb2数据的权限,让postfix可以读取
    # chmod 755 /etc/sasldb2

    6.测试smtp
    安装telnet
    # yum install telnet
    开始测试
    # telnet localhost 25
    返回:
    Trying ::1...
    Connected to localhost.
    Escape character is '^]'.
    220 mail.caefcs.com ESMTP Postfix

    EHLO caefcs.com
    AUTH LOGIN
    返回:334 VXNlcm5hbWU6
    要求进行smtp账号密码效验
    Y2hhcm1AY2FlZmNzLmNvbQ==
    postfix用户名的base64编码
    返回:334 UGFzc3dvcmQ6
    Y2hhcm0=
    密码的base64编码
    返回:235 2.7.0 Authentication successful
    helo caefcs.com
    返回:250 mail.caefcs.com
    mail from:charmaim@caefcs.com
    返回:250 2.1.0 Ok
    rcpt to:117056872@qq.com
    返回:250 2.1.5 Ok
    data
    返回:354 End data with <CR><LF>.<CR><LF>
    1jaflksofsajlkfasdj
    .
    返回:250 2.0.0 Ok: queued as 81D4F5807B0
    查看邮箱收到邮件。

    相关文章

      网友评论

          本文标题:Centos 配置postfix 服务器

          本文链接:https://www.haomeiwen.com/subject/iyqckqtx.html