Postfix

iRedMail配置静态路由

背景

邮箱默认 MX 记录指向梭子鱼邮件网关,所有外部邮件先经过网关过滤再投递到邮箱服务器。同时在 O365 上配置了 Connector,允许直接投递到网关。

需要将特定域的邮件通过静态路由(transport map)转发到指定地址,绕过默认投递逻辑。

配置步骤

1. 新建路由表文件

sudo touch /etc/postfix/staticroute

2. 编辑路由规则

sudo vi /etc/postfix/staticroute

格式为 目标域/收件人 转发目标:

# 整个域转发
example.com        smtp:[mail-gateway.example.com]

# 特定用户转发
user@example.com   smtp:[internal-server.example.com]

注意:[] 表示直接使用 IP/主机名解析,不查找 MX 记录。

3. 注册 transport_maps

编辑 /etc/postfix/main.cf,找到 transport_maps 行,在其下方添加:

transport_maps = hash:/etc/postfix/transport
    hash:/etc/postfix/staticroute

如果文件中已有 transport_maps,在末尾追加即可(多个映射源用空格分隔)。

4. 生成哈希文件并重载

sudo postmap /etc/postfix/staticroute
sudo systemctl reload postfix

5. 验证

查看当前路由是否生效:

postmap -q example.com /etc/postfix/staticroute

发送测试邮件,检查 maillog:

用postfix转发邮件到新的域名

公司换了新的域名和邮件系统,但临时无法把旧域名绑定到新的邮件系统。两套系统邮箱地址前缀相同,后缀不同,于是想到了用postfix做邮件转发。

  1. 新建/etc/postfix/virtual,内容为/^([^@]*)@olddomain/ $(1)@newdomain
  2. 编辑main.cf,在virtual_alias_maps = 后添加 regexp:/etc/postfix/virtual
  3. sudo systemctl reload postfix