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

Virtual domain variable in postfix/smtp_header_checks

· 52CE 我爱测

What Postfix virtual domain variable should I use in outgoing header creation? Current server I'm running a database-driven virtual domain server managed by PostfixAdmin . I want to put statements in the header of all outgoing em…

问题原文

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

What Postfix virtual domain variable should I use in outgoing header creation?

Current server

I'm running a database-driven virtual domain server managed by PostfixAdmin. I want to put statements in the header of all outgoing emails using the Postfix system, not using the responsible web app or client.

We need to produce...

The question is not about a List-Unsubscribe header, which we already know should look like...

in the email header :

List-Unsubscribe: mailto:[email omitted]

How we produce...

We already know to achieve that with a line tailored to outgoing checks /etc/postfix/smtp_header_checks. So, if we have this line...

main.cf :

smtp_header_checks = regexp:/etc/postfix/smtp_header_checks

(or some other setting like some_setting = regexp:/etc/postfix/some_setting?)

Then, we need in...

/etc/postfix/smtp_header_checks :

/^Content-Type:/i PREPEND List-Unsubscribe: mailto:[email omitted]

But, that only works for a specific domain somedomain.tld; I need a variable that depends on the sending domain.

There are no mydomain = settings anywhere in main.cf or any other /etc/postfix/ files; all domains are managed by the virtual domain maps managed by MySQL.

So, this question is about vmail variables any sending header creation, not only List-Unsubscribe:, as long as it works in creating List-Unsubscribe: from Postfix.

(Postfix docs aren't clear about usable vmail variables in headers.)

Code with domain variable

This is my best solution: $mydomain.

/etc/postfix/smtp_header_checks :

/^Content-Type:/i PREPEND List-Unsubscribe: mailto:unsubscribe@$mydomain

When sending from a virtual domain, is $mydomain the correct way to pass that domain into header or other email content creation sent by Postfix?


(Using Postfix for this is important so that all emails will have this, even those sent from the simple CLI or by third party web apps using PHP via MSMTP, et cetera. We already know how to add it via server lang header.)

已采纳解答

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

Postfix does not provide a built-in variable that directly corresponds to the sender's domain in smtp_header_checks, but we can use regex arguments from header_checks combined with smtp_header_checks to do the same thing.

First we use this custom header in

/etc/postfix/header_checks : add this

/^From:.*@(.*)/i PREPEND X-Sender-Domain:$1

Then prepend the List-Unsubscribe header using the custom X-Sender-Domain in

/etc/postfix/smtp_header_checks : we have

/^X-Sender-Domain:(.*)/i PREPEND List-Unsubscribe: mailto:unsubscribe@$1

Then make sure in

main.cf : we have

header_checks = regexp:/etc/postfix/header_checks
smtp_header_checks = regexp:/etc/postfix/smtp_header_checks

Then we reload with this command.

$ sudo postfix reload

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

资料来源与适用范围

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

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

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