美文网首页
云上那些事: postfix 使用中继模式发送邮件

云上那些事: postfix 使用中继模式发送邮件

作者: 善良能当饭吃吗 | 来源:发表于2019-06-20 15:26 被阅读0次

    背景:

    由于安全因素,阿里云会封掉25port, 这导致我们自建的监控系统无法发送邮件,因为是轻量型应用,申请解封失败,遂按照推荐的方式采用了465 port 和relay的模式进行告警邮件的发送

    组件构成:

    一个main,cf

    一个master.cf

    一个sasl_password  和生成的sasl_password.db

    一个generic 和生成的generic.db文件

    步骤:

    由于我们使用的是ubuntu18.04,所以此处以此为例:

    #安装postfix 

    apt upgrade

    apt install postfix  ,选择Internet Site ( 如果安装了sendmail 请将其停止或者卸载)

    #添加465端口发信

    vim /etc/postfix/master,cf

    添加 smtps inet n - - - - smtpd

    解除注释: -o smtpd_tls_wrappermode=yes

    !wq 保存退出

    vim /etc/services

    添加 smtps    465/tcp    mail2

            smtps    465/udp    mail2

    #创建相关授权文件及虚拟映射文件

    vim /etc/postfix/sasl_passwd

    [smtp.163.com]:465    username@163.com:授权码

    !wq  保存退出

    postmap /etc/postfix/sasl_passwd 生成sasl_passwd.db 文件

    vim /etc/postfix/generic

    root@monitor    username@163.com        (#要和上面文件内的一样)

    !wq 保存退出

    postmap /etc/postfix/generic    生成generic.db 文件

    #编辑主配置文件

    vim /etc/postfix/main.cf

    新增如下:

    smtp_sasl_auth_enable = yes

    #smtp_sasl_type = cyrus

    smtp_sasl_security_options=noanonymous

    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

    smtp_tls_security_level = encrypt

    smtp_tls_wrappermode = yes

    smtp_generic_maps = hash:/etc/postfix/generic

    修改如下:

    inet_protocols = ipv4

    #重启服务

    systemctl restart postfix

    测试发送,如有问题请检查log

    主要报错:

    1

    status=deferred (delivery temporarily suspended: lost connection with smtp.163.com[220.181.12.12] while receiving the initial server greeting)

    要配置relay 模式

    2:

    status=deferred (SASL authentication failed; cannot authenticate to server smtp.163.com[220.181.12.17]: no mechanism available)

    修改/etc/postfix/main.cf

    smtp_sasl_security_options=noanonymous

    3:

    status=bounced (host smtp.163.com[220.181.12.16] said: 553 Mail from must equal authorized user (in reply to MAIL FROM command))

    修改 /etc/postfix/generic 把主机名和邮箱名字修复正确。

    4

    postfix/smtp[3218]: SMTPS wrappermode (TCP port 465) requires setting "smtp_tls_wrappermode = yes", and "smtp_tls_security_level = encrypt" (or stronger)

    按照报错提示在主文件添加相关配置项

    参考资料:    https://itlaws.cn/post/postfix-use-external-smtp/

    相关文章

      网友评论

          本文标题:云上那些事: postfix 使用中继模式发送邮件

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