V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
mengjue
V2EX  ›  问与答

内网要如何架设 postfix 邮局?

  •  
  •   mengjue · 2016-04-21 20:49:56 +08:00 · 3067 次点击
    这是一个创建于 2933 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现在有一个内网的 gitlab ,需要一个邮件发送系统?但是这个服务器没有外网的 IP ,直接强上 postfix ,得到的是如下结果:

    postfix/smtp[15249]: 0A6B61AE1151: to=<[email protected]>, relay=sample.com[x.x.x.x]:25, delay=917, delays=917/0.01/0.04/0, dsn=4.4.2, status=deferred (lost connection with xxx while receiving the initial server greeting)
    

    似乎 relay 不对,然后我把 relay 改为我司的 exchange server 的 smtp ,然后返回需要 531 认证。似乎没有一个好办法能把邮箱发出去了?需要一个外部的不需要认证的 smtp relay server ?

    对运维不熟,知道的麻烦提个醒,谢谢。

    11 条回复    2016-08-13 12:08:49 +08:00
    pubby
        1
    pubby  
       2016-04-21 20:53:42 +08:00
    postfix 编译的时候记得加上 sasl 支持
    可以支持需要认证的 smtp 进行 relay 的。

    我就是 gitlab 通过 postfix 发信( relay 到阿里云的邮件推送服务)
    pubby
        2
    pubby  
       2016-04-21 21:00:03 +08:00
    relayhost = [smtp.mail.server]:25

    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/path/to/sasl_passwd
    smtp_sasl_mechanism_filter = plain, login


    ------- sasl_passwd -------
    [smtp.mail.server]:25 user:password


    记得 postmap /path/to/sasl_passwd 跑一下生成 sasl_passwd.map 文件
    mengjue
        3
    mengjue  
    OP
       2016-04-21 22:58:05 +08:00
    阿里云的推送是要收费的,如果要搞免费的,不知道 relay server 是否受到 relay server 的 smtp 的垃圾邮件的策略限制?
    dynaguy
        4
    dynaguy  
       2016-04-22 13:14:07 +08:00
    postfix 有点杀鸡牛刀了。装个 mailx , 配个用户账号就行了。
    guoxu1231
        5
    guoxu1231  
       2016-08-10 22:45:01 +08:00
    @pubby 你阿里云邮件推送能成功吗? 我试了很多次都不行, 但是 gmail 倒是可以.
    pubby
        6
    pubby  
       2016-08-10 23:19:39 +08:00
    @guoxu1231 可以啊,我的一些服务器状态报告都是 postfix relay 到阿里云邮件推送的
    guoxu1231
        7
    guoxu1231  
       2016-08-11 15:43:19 +08:00
    @pubby 方便分享你的 postfix 配置吗?
    我用了一个 postfix 的 docker 镜像,
    https://github.com/juanluisbaptiste/docker-postfix
    更改了 relayhost = [$SMTP_SERVER]:587" 成 25 端口, 也尝试添加 smtp_sasl_mechanism_filter = plain, login, 但还是不成功. 提阿里云工单咨询客服人员, 客服人员的回答是 邮件推送(direct mail)目前不支持 smtp delay 的用法....
    https://github.com/juanluisbaptiste/docker-postfix/blob/master/run.sh
    pubby
        8
    pubby  
       2016-08-11 16:40:42 +08:00
    @guoxu1231 确保阿里云>邮件推送>发信地址 SMTP 密码设置之类的都 OK

    main.cf:

    relayhost = [smtpdm.aliyun.com]:465
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/usr/local/etc/postfix/sasl_passwd
    smtp_sasl_mechanism_filter = plain, login
    smtp_tls_loglevel = 1
    smtp_use_tls = yes
    smtp_enforce_tls = yes
    # CA 文件如果没有的话,从另外的包安装一下
    smtp_tls_CAfile = /usr/local/share/certs/ca-root-nss.crt
    smtp_sasl_security_options =
    smtp_sasl_tls_security_options = noanonymous
    smtp_tls_wrappermode = yes
    smtp_tls_security_level = encrypt


    sasl_passwd 文件:
    [smtpdm.aliyun.com]:465 [email protected]:阿里云 SMTP 设的密码
    # 这个文件需要 postmap sasl_passwd 处理一下才能使用


    # 测试
    echo "test" |mail -s "test title" [email protected]

    如果有问题的话,看 postfix 的日志,一般都能找到问题
    guoxu1231
        9
    guoxu1231  
       2016-08-12 00:25:20 +08:00
    @pubby 似乎不太行, 报错.
    (lost connection with smtpdm.aliyun.com[110.75.48.181] while receiving the initial server greeting)
    客服的回复是:
    售后工程师 : 您好,邮件推送并不是一个转发服务,不支持中继邮件,且通过调用邮件推送 smtp 接口发信需要有账户认证,中继可能会产生认证失败无法发送。

    用 gmail 的 smtp relay 倒是一次就成功了.
    pubby
        10
    pubby  
       2016-08-12 00:56:12 +08:00
    @guoxu1231 我这里可以

    Aug 12 00:01:00 dev postfix/pickup[50246]: 773471B822: uid=1001 from=<pubby>
    Aug 12 00:01:00 dev postfix/cleanup[53100]: 773471B822: message-id=<[email protected]>
    Aug 12 00:01:00 dev postfix/qmgr[64627]: 773471B822: from=<[email protected]>, size=354, nrcpt=1 (queue active)
    Aug 12 00:01:01 dev postfix/smtp[53104]: Verified TLS connection established to smtpdm.aliyun.com[110.75.48.181]:465: TLSv1 with cipher AES256-SHA (256/256 bits)
    Aug 12 00:01:01 dev postfix/smtp[53104]: 773471B822: to=<[email protected]>, relay=smtpdm.aliyun.com[110.75.48.181]:465, delay=1.2, delays=0.33/0.26/0.53/0.08, dsn=2.0.0, status=sent (250 Data Ok: queued as freedom ###envid=82880264085)
    Aug 12 00:01:01 dev postfix/qmgr[64627]: 773471B822: removed


    你要么再加上 sender 重写规则,把所有邮件发信人改写成你的阿里云邮件推送的发信地址

    main.cf 里加上:
    sender_canonical_maps = pcre:/usr/local/etc/postfix/sender_canonical_map

    sender_canonical_map 内容:
    /.*/ [email protected]

    # 所有发件人都改写成 [email protected]
    # 同样需要 postmap sender_canonical_map 预处理一下这个文件


    我这边确是也有这样的设置
    guoxu1231
        11
    guoxu1231  
       2016-08-13 12:08:49 +08:00
    碰到了新的错误.
    TLS is required, but was not offered by host smtpdm.aliyun.com[110.75.48.181]
    可能目前阿里云邮件推送对于 SMTP 中继支持的还是不完善, 文档也没有任何提及.

    不像 AWS 的 Simple Email Service, 在 FAQ 里明确提到了支持 SMTP 中继:
    Amazon SES 提供功能全面的 SMTP 接口,以实现与能够通过 SMTP 发送电子邮件的应用程序的无缝集成。 您可从应用程序直接连接至此 SMTP 接口,或将现有电子邮件服务器配置为使用此接口作为 SMTP 中继。
    可将 Amazon SES 发送功能与 Sendmail 、 Postfix 和 Exim 等常用邮件传输代理 (MTA) 相集成。您甚至可从命令行连接到 SMTP 接口,直接发送 SMTP 命令.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2206 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 02:40 · PVG 10:40 · LAX 19:40 · JFK 22:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.