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

Execute script when new email arrives (Postfix / Dovecot)

· 52CE 我爱测

I want to execute a backup script (.sh) when I receive a new mail on my mailserver (running on Debian with Postfix / Dovecot). I've found many posts on this topic, but no one give me a working solution. Here the last solution I h…

问题原文

原帖链接 · soywod · CC BY-SA 3.0

I want to execute a backup script (.sh) when I receive a new mail on my mailserver (running on Debian with Postfix / Dovecot). I've found many posts on this topic, but no one give me a working solution. Here the last solution I have tested : https://stackoverflow.com/questions/27230324/run-script-when-postfix-dovecot-get-new-mail. Does anyone have a suggestion ?

EDIT: When I receive a new mail, I want to run a bash script AND let postfix/dovecot put this new mail in the ~/Maildir folder. I'm looking for a kind of "middleware" that will not block the standard process

已采纳解答

原帖链接 · HBruijn · CC BY-SA 3.0

If your actual question is on how to retain a backup of every message received (and sent) by your mailserver, the answer is to set the option always_bcc and specify a mailbox.

Depending on your setup you can forward messages received by that mailbox (or alias) to a script for further processing.

For instance in /etc/aliases:

 mailbox: "| /usr/local/bin/script.pl"

Edit based on comments:

Quite old school, but when your email users are system users and have home directories, there is the old sendmail style .forward file, still supported by postfix as well. The syntax is a bit arcane, but a ~mailuser/.forward wiith the following contents will both deliver the message to the users mailstore and forward it to a script:

\mailbox, "| /usr/local/bin/script.pl"

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

资料来源与适用范围

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

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

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