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

Configure postfix virtual transport to deliver mail to arbitrary (local) addresses

· 52CE 我爱测

I'm using Postfix in a very niche application with no inbound or outbound SMTP connectivity (other than via the loopback interface). I would like to configure the postfix virtual transport to deliver mail to local files for arbit…

问题原文

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

I'm using Postfix in a very niche application with no inbound or outbound SMTP connectivity (other than via the loopback interface).

I would like to configure the postfix virtual transport to deliver mail to local files for arbitrary addresses matching a specific pattern. That is, assuming that the final transport is virtual, I would like mail to foo0 to get delivered to /var/vmail/foo0, mail for foo100 to go to /var/vmail/foo100, etc. The files should all be owned by the same uid/gid, managed via static virtual_uid_maps and virtual_gid_maps.

The catch is that the specific target addresses aren't known in advance.

What I really want is something like:

virtual_mailbox_maps = regexp:/etc/postfix/vmailbox

With vmailbox containing something like:

/^(foo[0-9]*)(@.*)?/ ${1}

But the virtual transport explicitly does not support regular expression substitution...nor does it support the socketmap table type, which would be another way of solving this particular issue.

I guess I could solve this with a custom transport, but I was hoping to not write an MDA.

Is there any way to make this work?

已采纳解答

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

With a little additional research, this turned out to be easier than I thought.

In main.cf:

mydestination = localhost

# leave valid recipient checking up to the mda
local_recipient_maps =

# don't permit any outbound mail
default_transport = error:No outbound mail delivery!

# look up transport via transport map
transport_maps = lmdb:transport

In transport:

# deliver root locally
root@localhost  local:localhost

# deliver everything else via our fakemail transport
*               fakemail:

In master.cf:

fakemail unix  -       n       n       -       -       pipe
        flags=DBFRXhu directory=/var/spool/vmail user=fakemail:fakemail
        argv=/usr/local/bin/fakemail ${user}

And in fakemail:

#!/bin/sh

umask 007
cat >> "$1"

With the above configuration, echo test message | mail -s test root goes to /var/mail/root. Any other unqualified address gets delivered via the fakemail script to /var/spool/vmail/<user>. E.g.:

# echo test message | mail -s test1 user001
# echo test message | mail -s test2 user001
# mail -f /var/spool/vmail/user001
Mail version 8.1.2 01/15/2001.  Type ? for help.
"/var/spool/vmail/user001": 2 messages 2 new
>N  1 root@localhost     Sat Nov 11 20:40   16/482   test1
 N  2 root@localhost     Sat Nov 11 20:40   16/482   test2

We could obviously replace the fakemail script with something more robust, perhaps implementing some simple pattern matching there, etc.

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

资料来源与适用范围

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

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

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