大网数据广告活动
服务器运维问答

How to make postfix sign non-delivery notifications with DKIM?

· 52CE 我爱测

I have set up my "postfix" server to sign outgoing messages with DKIM and verified that it works correctly for SMTP users using authentication. However, "non-delivery notifications", i.e. mails that are sent automatically from th…

问题原文

原帖链接 · mist · CC BY-SA 4.0

I have set up my "postfix" server to sign outgoing messages with DKIM and verified that it works correctly for SMTP users using authentication. However, "non-delivery notifications", i.e. mails that are sent automatically from the server itself, are not being signed and are therefore rejected by some recipients during forwarding. What system exactly sends those messages, via which channel and how can I change the configuration to make sure they are also signed?

The DKIM-related part of /etc/postfix/main.cf:

# Milter configuration
milter_default_action = accept
milter_protocol = 6
smtpd_milters = local:opendkim/opendkim.sock
non_smtpd_milters = $smtpd_milters

The OpenDKIM configuration file /etc/opendkim.conf:

Syslog                yes
Logwhy                yes
UMask                 007

Canonicalization      relaxed/simple
Mode                  sv
SubDomains            no

AutoRestart           yes
AutoRestartRate       10/1M
Background            yes
DNSTimeout            5
SignatureAlgorithm    rsa-sha256

Socket                local:/var/spool/postfix/opendkim/opendkim.sock

PidFile               /var/run/opendkim/opendkim.pid

OversignHeaders       From

TrustAnchorFile       /usr/share/dns/root.key

UserID                opendkim

KeyTable              refile:/etc/opendkim/key.table
SigningTable          refile:/etc/opendkim/signing.table

ExternalIgnoreList    /etc/opendkim/trusted.hosts

InternalHosts         /etc/opendkim/trusted.hosts

Most of the headers of a non-delivery notification that did make it to its destination (despite not being signed):

Return-Path: <>
X-Original-To: [email omitted]
Delivered-To: [email omitted]
Received: from mail.primary-domain.com
    by mail.otherdomain.com (Postfix) with ESMTPS id CC9F8BB862
    for <[email omitted]>; [...date removed...]
Received: by mail.primary-domain.com (Postfix)
    id 1073CBB8A8; [...date removed...]
Date: [...removed...]
From: [email omitted] (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
To: [email omitted]
Auto-Submitted: auto-replied
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
    boundary="D80F1BB862.1696269305/mail.primary-domain.com"
Message-Id: <[email omitted]>
Content-Transfer-Encoding: 7bit

/etc/opendkim/trusted.hosts:

127.0.0.1
localhost

.otherdomain.com
.primary-domain.com

/etc/opendkim/signing.table:

*@otherdomain.com      default._domainkey.otherdomain.com
*@*.otherdomain.com    default._domainkey.otherdomain.com
*@primary-domain.com   default._domainkey.primary-domain.com
*@*.primary-domain.com default._domainkey.primary-domain.com

Update

On suggestion of @NikitaKipriyanov I increased the log level:

Syslog                  yes
LogWhy                  yes
MilterDebug             9

Weirdly, this didn't produce any logs about any outgoing message (neither the "normal" messages, which are being signed correctly, nor the NDNs, which are not being signed).

已采纳解答

原帖链接 · Nikita Kipriyanov · CC BY-SA 4.0

After reading Postfix MILTER Readme more carefully I found this paragraph:

Signing internally-generated bounce messages

Postfix normally does not apply content filters to mail that is generated internally such as bounces or Postmaster notifications. Filtering internally-generated bounces would result in loss of mail when a filter rejects a message, as the resulting double-bounce message would almost certainly also be blocked.

To sign Postfix's own bounce messages, enable filtering of internally-generated bounces (line 2 below), and don't reject any internally-generated bounces with non_smtpd_milters, header_checks or body_checks (lines 3-5 below).

1 /etc/postfix/main.cf:
2     internal_mail_filter_classes = bounce
3     non_smtpd_milters = don't reject internally-generated bounces
4     header_checks = don't reject internally-generated bounces
5     body_checks = don't reject internally-generated bounces

It turns out, this is likely a problem with Postfix configuration. Set in main.cf:

internal_mail_filter_classes = bounce

On the other hand, the man postconf page has the following warning regarding this option:

NOTE: It's generally not safe to enable content inspection of Postfix-generated email messages. The user is warned.

I think the purpose of the warning is to remind again that milter must not REJECT a message. Make sure it only signs.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-10-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。