You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Postfix配置邮件管道至脚本失效问题求助

Troubleshooting Postfix Pipe-to-Script Configuration Not Taking Effect

Let’s walk through the most common issues that might be preventing your Postfix setup from routing emails to your script. I’ve dealt with this exact problem before, so here’s what to check step by step:

1. Verify Your master.cf Entry Format

Postfix is extremely strict about whitespace and structure in master.cf. Make sure your new service line follows this exact pattern (no extra spaces, correct ordering):

my_script    unix  -       n       n       -       -       pipe
  flags=DRhu user=your_user argv=/full/path/to/your/script.sh ${sender} ${recipient}
  • The first line defines the service name (my_script), transport type (unix), and default flags (the - values can stay as-is).
  • The second line must be indented with spaces (not tabs!) and includes critical details: the user to run the script as, and the full path to your script with placeholders for sender/recipient.

2. Ensure You’ve Configured a Transport Map

Adding the service to master.cf isn’t enough—you need to tell Postfix when to use it. Here’s how:

  • Add this line to /etc/postfix/main.cf:
    transport_maps = hash:/etc/postfix/transport
    
  • Create /etc/postfix/transport with this content (to route all emails to your script):
    *    my_script:
    
  • Run postmap /etc/postfix/transport to compile the map into a hash file (Postfix requires this compiled version to read the rules).
  • Restart Postfix again after this change.

3. Check Script Permissions & Executability

Postfix’s runtime user (usually postfix, or the user= you specified in master.cf) needs full access to run the script:

  • Make the script executable: chmod +x /full/path/to/your/script.sh
  • Ensure the shebang at the top of the script matches your system’s interpreter (e.g., #!/bin/bash or #!/usr/bin/python3).
  • Verify the Postfix user can read and traverse all directories leading to the script (e.g., chmod o+x /path/to/script/directory if needed).

4. Dig Into Postfix Logs

Logs are your best tool for pinpointing issues. Check the mail log (location varies by distro: /var/log/mail.log on Debian/Ubuntu, /var/log/maillog on RHEL/CentOS) after sending a test email. Look for lines containing:

  • Your service name (my_script)
  • The word pipe
  • Error messages like "permission denied", "command not found", or "invalid argument".
    Example log search: grep -i "my_script\|pipe" /var/log/mail.log

5. Validate Postfix Configuration

Run postfix check to catch any syntax errors in master.cf or main.cf. This will flag issues like missing fields, incorrect config file permissions, or invalid service names.

6. Test the Transport Map

Confirm your transport rule is being recognized by running:

postmap -q "test@example.com" /etc/postfix/transport

You should see my_script: in the output—if not, recheck your transport file and re-run postmap.

Start with these steps, and the logs will almost certainly point you to the exact issue. It’s usually a missing transport map, incorrect master.cf formatting, or a permissions problem with the script.

内容的提问来源于stack exchange,提问作者zekorius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:26:48