-3

我有:

postfix->dovecot-> new mail go to [aaaa@11111.xemple.com] mailbox 
postfix->dovecot-> new mail go to [aaaa@22222.xemple.com] mailbox 
postfix->dovecot-> new mail go to [aaaa@33333.xemple.com] mailbox 

我需要在收到邮件时运行脚本并由 dovecot 为域 22222.xemple.com 保存

当新邮件到达aaaa@22222.xemple.com dovecot 运行脚本时如何制作:sh /my/script/run/after/new/email/in/22222_xemple_com/run.sh

4

4 回答 4

2

使用后缀传输!

  1. 添加将运行命令transpostfix的用户

  2. 添加到 master.cf 新传输:

    emailtransport   unix  -       n       n       -       -       pipe
        flags=X user=transpostfix  size=26214400 argv=/my/script/run/after/new/email/in/22222_xemple_com/run.sh
    
  3. 添加到 main.cf 链接以传输文件

    transport_maps = hash:/etc/postfix/transport
    
  4. 编辑传输文件并运行 postmap

    #   postmap /etc/postfix/transport
    transpostfix@localhost.localhost    emailtransport:
    
  5. 添加密件抄送。一封邮件发送到 Dovecot,第二封邮件发送到脚本。在 main.cf 中编辑:

    recipient_bcc_maps = hash:/etc/postfix/recipient_bcc_maps
    
  6. /etc/postfix/recipient_bcc_maps

    ###    postmap /etc/postfix/recipient_bcc_maps
    aaaa@11111.xemple.com run_script@example.commm
    
  7. 添加 main.cf 选项virtual_alias_maps 并从 run_script@example.commm 重定向邮件 goto transpostfix@localhost.localhost

于 2016-05-17T23:39:59.697 回答
1

使用鸽舍,您可以使用鸽笼。

这是 dovecot 的官方链接: https ://wiki2.dovecot.org/Pigeonhole/Sieve/Plugins/Extprograms

它与 sieve 服务器一起用于过滤邮件,因此您可以轻松选择应将哪些邮件发送到您的脚本。

玩得开心

于 2020-02-15T14:27:37.820 回答
0

使用incron

/var/spool/incron:

/var/vmail/22222.xemple.com/aaaa/new IN_MOVED_TO,IN_ONESHOT /sys_my/postfix-mail/checker_postfix-parser.sh

---------------------停止阅读!较旧的解决方案不好---- 我使用其他程序来做到这一点https://github.com/rvoicilas/inotify-tools/wiki#info

服务器:centos 6

脚本postfix-parser.sh测试是否有新字母进入文件夹:

#!/bin/bash
###
### sh /sys_my/postfix-mail/postfix-parser.sh
while ((i<=END)); do
EVENT=$(inotifywait --format '%e' /var/vmail/22222.xemple.com/aaaa/new)
if [ "$EVENT" == "CREATE" ]; then 
echo $EVENT 
let ii++
echo $ii
fi
done

脚本checker_postfix-parser.sh检查脚本是否运行:

#!/bin/bash
###
# sh /sys_my/postfix-mail/checker_postfix-parser.sh

result=`ps aux | grep -i "postfix-parser.sh" | grep -v "grep" | wc -l`
if [ $result -ge 1 ]
   then
        echo "script is running"
   else
    sh /sys_my/postfix-mail/postfix-parser.sh
fi

添加到启动:添加此行:

sh /sys_my/postfix-mail/checker_postfix-parser.sh

归档:

/etc/rc.d/rc.local

每 5 分钟在 cron 中运行检查器:

*/1 * * * * root sh /sys_my/postfix-mail/checker_postfix-parser.sh
于 2014-12-02T09:27:58.873 回答
0

正如@Wim 所建议的那样,我发现配置 Dovecot 是一种更优雅的解决方案(与配置 Postfix 不同)。步骤如下:

  1. 在目录中创建您的脚本(即。mail_processor.py/usr/lib/dovecot/sieve-execute/

    #!/usr/bin/python3
    from sys import stdin
    with open('/var/log/mail_processor.log', 'a') as logfile:
        for line in stdin:
            print(line.rstrip(), file=logfile)
    
    • 确保您的脚本和目标文件具有正确的权限:

      $ chmod +rx /usr/lib/dovecot/sieve-execute/mail_processor.py
      $ chmod 0777 /var/log/mail_processor.log
      
  2. 启用sieve_extprograms插件:

    • 用以下内容修改\etc\dovecot\conf.d\90-sieve.conf插件部分:

      sieve_extensions = +vnd.dovecot.execute
      sieve_plugins = sieve_extprograms
      sieve_execute_bin_dir = /usr/lib/dovecot/sieve-execute
      
    • 重新加载鸽舍:

      $ service dovecot restart
      
  3. 创建筛滤器(即在 Roundcube goto settings-> filters-> actions->中edit filter set):

    require ["vnd.dovecot.execute"];
    # rule:[mail processing]
    if true
    {
        execute :pipe "mail_processor.py";
    }
    

现在,使用此筛子过滤器发送到任何邮箱的所有邮件都将通过管道mail_processor.py进行操作。

Pigeonhole Sieve:Extprograms Plugin文档供参考

于 2021-05-11T05:43:46.157 回答