📬 在实现 valid_recipients 后,Postfix 重复出现警告和连接问题

如何重新加载 Postfix 以配合 Discourse AI

Ethsim2:

我修改了 main.cf,这是正确的吗?

DiscourseHelper:

搜索

搜索内容:在 Discourse 邮件接收器容器中实施 valid_recipients 文件以进行收件人限制时,是否有必要或建议手动修改 Postfix main.cf?是否应直接编辑 main.cf,还是 Discourse 邮件接收器设置的所有推荐更改都通过 docker 环境变量或 launcher yml 设置来处理?

阅读

阅读:📬 在实施 valid_recipients 后重复出现 Postfix 警告和连接

在遵循 Discourse 的标准设置时,在邮件接收器容器中手动修改 main.cf 来过滤有效收件人是必要或不推荐的。

正确方法:
Discourse 的官方邮件接收器指南和容器设置旨在让您无需手动编辑 main.cf。相反:

  • 您应该使用 mail-receiver.ymlenv 部分来设置 Postfix 参数——特别是使用环境变量,例如:

    POSTCONF_smtpd_recipient_restrictions: texthash:/etc/postfix/valid_recipients
    

    或者,如果您使用旧的配置样式:

    POSTCONF_smtpd_recipient_restrictions: check_recipient_access hash:/etc/postfix/valid_recipients, reject
    
  • Docker/launcher 会在容器启动时正确应用这些设置,将它们注入 Postfix,而无需直接编辑文件。

直接编辑 main.cf 可能会导致冲突,或者在容器重建时被覆盖。这样也很容易出错(例如文件格式或收件人映射)。

关于您的错误:
您看到的警告:

warning: /etc/postfix/valid_recipients, line 1: expected format: key whitespace value -- ignoring this line

是由格式错误的 valid_recipients 文件引起的——而不是由配置设置方式(环境变量 vs main.cf)引起的。请确保您的条目如下所示:

alloweduser@yourdomain.com OK
another@yourdomain.com OK
default REJECT

没有冒号、等号或逗号——只有地址、空格和 OK(或 REJECT)。


除非您有非常高级的、完全自定义的配置并且确切地知道自己在做什么,否则请勿直接编辑 main.cf
所有正常指令(包括有效收件人和发件人过滤)都通过在 mail-receiver.yml 中设置环境变量来执行。


参考资料:

总结:
对于标准的 Discourse 邮件接收器设置,您通常不需要触碰 main.cf。在 yml 中设置环境变量是推荐且受支持的方式。对于收件人映射,请始终使用正确的哈希/文本哈希格式和正确的文件语法。


实际上我已经完全删除了自定义配置,使用了此处描述的配置,并且我的邮件测试运行正常。

检测到 x86_64 架构。
确保 launcher 已更新
正在获取 origin
Launcher 已更新
正在停止旧容器
+ /usr/bin/docker stop -t 600 mail-receiver
mail-receiver
release: 正在从 discourse/mail-receiver 拉取
Digest: sha256:2a0d45bb92a783c846a821e635413764eeadb3441ef6190085545a4[已隐藏 9 位数字]
Status: 镜像已是最新版本 discourse/mail-receiver:release
docker.io/discourse/mail-receiver:release
ERROR:  找不到 Ruby 库文件或共享库 pups
cd /pups && /pups/bin/pups --stdin
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
sha256:[已隐藏 6 位数字]69734d779a95ec83c7103dc2fc04f1d690ebde62[已隐藏 18 位数字]
[已隐藏 64 位 API 密钥?]
正在移除旧容器
+ /usr/bin/docker rm mail-receiver
mail-receiver

+ /usr/bin/docker run --shm-size=512m -d --restart=always -e LANG=en_US.UTF-8 -e LC_ALL=en_US.UTF-8 -e LANGUAGE=en_US.UTF-8 -e MAIL_DOMAIN=discourse. MYDOMAINNAME.com -e DISCOURSE_BASE_URL=https:// MYDOMAINNAME.com -e DISCOURSE_API_KEY=[已隐藏 64 位 API 密钥] -e DISCOURSE_API_USERNAME=system -h ubuntu-mail-receiver -e DOCKER_HOST_IP=172.17.0.1 --name mail-receiver -t -p 25:25 -v /var/discourse/shared/mail-receiver/postfix-spool:/var/spool/postfix --mac-address [已隐藏 MAC 地址] local_discourse/mail-receiver /sbin/boot
[已隐藏 64 位 API 密钥?]
root@ubuntu:/var/discourse# ./launcher logs mail-receiver
检测到 x86_64 架构。
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Operating environment:
HOSTNAME=ubuntu-mail-receiver
LANGUAGE=en_US.UTF-8
MAIL_DOMAIN=discourse.MYDOMAINNAME.com
DOCKER_HOST_IP=172.17.0.1
PWD=/
DISCOURSE_BASE_URL=https:// MYDOMAINNAME.com
HOME=/root
LANG=en_US.UTF-8
TERM=xterm
SHLVL=1
DISCOURSE_API_USERNAME=system
LC_ALL=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
INCLUDE_DMARC=true
DISCOURSE_API_KEY=[已隐藏 64 位 API 密钥]
_=/usr/bin/env
将发送到 discourse. MYDOMAINNAME.com 的邮件投递到 Discourse
正在启动 OpenDKIM...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US.UTF-8",
        LC_ALL = "en_US.UTF-8",
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
将用户 `postfix' 添加到组 `opendkim' ...
<86>Jul 23 13:27:19 usermod[16]: add 'postfix' to group 'opendkim'
<86>Jul 23 13:27:19 usermod[16]: add 'postfix' to shadow group 'opendkim'Done.
正在启动 OpenDMARC...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = "en_US.UTF-8",
        LC_ALL = "en_US.UTF-8",
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
<22>Jul 23 13:27:19 opendkim[24]: OpenDKIM Filter v2.11.0 starting (args: -x /etc/opendkim.conf)将用户 `postfix' 添加到组 `opendmarc' ...
<86>Jul 23 13:27:19 usermod[31]: add 'postfix' to group 'opendmarc'
<86>Jul 23 13:27:19 usermod[31]: add 'postfix' to shadow group 'opendmarc'Done.
<22>Jul 23 13:27:19 opendmarc[39]: OpenDMARC Filter v1.4.2 starting (args: -c /etc/opendmarc.conf)
<22>Jul 23 13:27:19 opendmarc[39]: additional trusted authentication services: (none)
postfix: Postfix is using backwards-compatible default settings
Jul 23 13:27:19 ubuntu-mail-receiver postfix[51]: Postfix is using backwards-compatible default settings
postfix: See http://www.postfix.org/COMPATIBILITY_README.html for details
Jul 23 13:27:19 ubuntu-mail-receiver postfix[51]: See http://www.postfix.org/COMPATIBILITY_README.html for details
postfix: To disable backwards compatibility use "postconf compatibility_level=3.6" and "postfix reload"
Jul 23 13:27:19 ubuntu-mail-receiver postfix[51]: To disable backwards compatibility use "postconf compatibility_level=3.6" and "postfix reload"
正在启动 Postfix
Jul 23 13:27:19 ubuntu-mail-receiver postfix/master[1]: daemon started -- version 3.7.11, configuration /etc/postfix
Jul 23 13:27:53 ubuntu-mail-receiver postfix/smtpd[122]: connect from mail-il1-f180.google.com[209.85.166.180]
<22>Jul 23 13:27:54 policyd-spf[129]: : prepend Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.166.180; helo=mail-il1-f180.google.com; envelope-from= person@gmail.com; receiver=discourse. MYDOMAINNAME.com
Jul 23 13:27:54 ubuntu-mail-receiver postfix/smtpd[122]: BC6D71BF9C8: client=mail-il1-f180.google.com[209.85.166.180]
Jul 23 13:27:54 ubuntu-mail-receiver postfix/cleanup[130]: BC6D71BF9C8: message-id=<CWXP1[已隐藏 8 位数字]81B627937FA7F4B2CE65A15FA@CWXP123MB2918.GBRP123.PROD.OUTLOOK.COM>
<22>Jul 23 13:27:55 opendkim[24]: BC6D71BF9C8: DKIM verification successful
<22>Jul 23 13:27:55 opendkim[24]: BC6D71BF9C8: s=20230601 d=gmail.com a=rsa-sha256 SSL
<22>Jul 23 13:27:55 opendmarc[39]: implicit authentication service: ubuntu-mail-receiver.localdomain
<22>Jul 23 13:27:55 opendmarc[39]: BC6D71BF9C8: gmail.com pass
Jul 23 13:27:55 ubuntu-mail-receiver postfix/qmgr[120]: BC6D71BF9C8: from=<person@gmail.com>, size=75533, nrcpt=1 (queue active)
Jul 23 13:27:55 ubuntu-mail-receiver postfix/smtpd[122]: disconnect from mail-il1-f180.google.com[209.85.166.180] ehlo=1 mail=1 rcpt=1 bdat=2 quit=1 commands=6
<23>Jul 23 13:27:55 receive-mail[133]: Recipient: person.REDACTED@discourse. MYDOMAINNAME.com
Jul 23 13:27:55 ubuntu-mail-receiver postfix/pipe[132]: BC6D71BF9C8: to=< person.REDACTED@discourse. MYDOMAINNAME.com>, relay=discourse, delay=1.8, delays=1.6/0.01/0/0.22, dsn=2.0.0, status=sent (delivered via discourse service)
Jul 23 13:27:55 ubuntu-mail-receiver postfix/qmgr[120]: BC6D71BF9C8: removed