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

postfix: custom relayhost for any-subdomain of a specific domain?

· 52CE 我爱测

What is the right way to add a different relay for "from" email addresses with a specific domain and any subdomain for them? Or in other words, what am I doing wrong? How would you change postfix configuration to make it work? Th…

问题原文

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

What is the right way to add a different relay for "from" email addresses with a specific domain and any subdomain for them? Or in other words, what am I doing wrong? How would you change postfix configuration to make it work?

This is an internal relay - not connected to the internet. The goal is to:

  1. Send emails with "from" addresses *@domainB.com and *@*.domainB.com to a special relay dedicated to that domain (smtp.domainB.com), while:
  2. Send everything else - to the default relay.

P.S. It's plain vanilla CentOS 7.7. Postfix 2.10.1. This /etc/postfix/relay_maps only works for the domain but not subdomains:

domainB.com      [smtp.domainB.com]:25
.domainB.com     [smtp.domainB.com]:25

(...and yes, I run the following after updating the file:

sudo postmap /etc/postfix/relay_maps
sudo systemctl restart postfix

)

P.P.S. Also, the following line was added to /etc/postfix/main.cf:

sender_dependent_relayhost_maps = hash:/etc/postfix/relay_maps

已采纳解答

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

You have the option sender_dependent_relayhost_maps , this option is avalalabe since Postfix 2.3 .

So the option is avalaible on CENTOS 7

root@test-cs-7 ~]# rpm -qa postfix
postfix-2.10.1-9.el7.x86_64
[root@test-cs-7 ~]# postconf  | grep ^sender_dependent_relayhost_maps
sender_dependent_relayhost_maps =

A very simple example :

add this section at the end of /etc/postfix/main.cf

sender_dependent_relayhost_maps = pcre:/etc/postfix/sender_dependent_relayhost

create a file /etc/postfix/sender_dependent_relayhost with this content :

/^boss@example\.com/    [192.168.8.2]
/^boss@example\.net/    [192.168.8.1]
/^.*@.*\.example\.com/  [192.168.8.3]
/^.*@.*\.example\.net/  [192.168.8.4]
/^.*@example\.net/  [192.168.8.2]
/^.*@example\.com/  [192.168.8.1]
/^.*@example\.net/  [192.168.8.2]

About option :

About prce table :

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

资料来源与适用范围

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

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

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