Ubuntu – Catch all emails and pipe them all to a script with postfix

bashemailpostfixsmtpUbuntu

I realize this question was asked and answer before. Here's what I have done.

Created a catchall address and user. Here is my /etc/postfix/virtual file.

@example.com catchall

Added it to main.cf. Here is the entry.

virtual_alias_maps = hash:/etc/postfix/virtual

This worked and all my mail went to /var/mail/catchall which was good. Next I wanted to create a pipe that runs a program each time an email is received. To accomplish this I created a /etc/postfix/transport

example.com catchall:

Then I added this to my master.cf file.

catchall  unix  -       n       n       -       -       pipe
  flags=F user=catchall argv=/tmp/test.sh

test.sh is just a tiny shell script so I can see that my code runs.

#!/bin/bash
echo `whoami` > /tmp/aaa.txt

Finally, I ensured that the catchall user can run this script with su -c "/tmp/test.sh " catchall, which outputs catchall to the expected aaa.txt.

So my question is, what gives? What am I missing? Any help? I've read the docs, read tutorials, and I just can't get it working. The catchall address works properly, I see mail being received in mail.log, mail.err is empty, and I've run postmap on all of my files and done a postfix reload after editing the files. But my shell script won't run….

postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = all
mailbox_size_limit = 0
mydestination = twinsen.example.com, myhostname, localhost.localdomain, localhost
myhostname = mydomain-guts
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
transport_maps = hash:/etc/postfix/transport
virtual_alias_maps = hash:/etc/postfix/virtual

mail.log

Jan 11 22:18:02 mydomain-guts postfix/smtpd[3835]: connect from mail-we0-f172.google.com[74.125.82.172]
Jan 11 22:18:02 mydomain-guts postfix/smtpd[3835]: 790E01400D4: client=mail-we0-f172.google.com[74.125.82.172]
Jan 11 22:18:02 mydomain-guts postfix/cleanup[3834]: 790E01400D4: message-id=<CA+wDdVbiDS=Kpa7nMA4-y5GCMgo0PcsK4G5Kb_uE_xKHBYY+vQ@mail.gmail.com>
Jan 11 22:18:02 mydomain-guts postfix/qmgr[3829]: 790E01400D4: from=<mygmail@gmail.com>, size=1828, nrcpt=1 (queue active)
Jan 11 22:18:02 mydomain-guts postfix/smtp[3831]: 790E01400D4: to=<catchall@example.com>, orig_to=<kik@twinsen.example.com>, relay=none, delay=0.24, delays=0.2/0/0.04/0, dsn=5.4.6, status=bounced (mail for example.com loops back to myself)
Jan 11 22:18:02 mydomain-guts postfix/cleanup[3834]: B3E2F1400D9: message-id=<20150112031802.B3E2F1400D9@mydomain-guts>
Jan 11 22:18:02 mydomain-guts postfix/qmgr[3829]: B3E2F1400D9: from=<>, size=3677, nrcpt=1 (queue active)
Jan 11 22:18:02 mydomain-guts postfix/bounce[3832]: 790E01400D4: sender non-delivery notification: B3E2F1400D9
Jan 11 22:18:02 mydomain-guts postfix/qmgr[3829]: 790E01400D4: removed
Jan 11 22:18:02 mydomain-guts postfix/smtpd[3835]: disconnect from mail-we0-f172.google.com[74.125.82.172]
Jan 11 22:18:03 mydomain-guts postfix/smtp[3831]: B3E2F1400D9: to=<mygmail@gmail.com>, relay=gmail-smtp-in.l.google.com[64.233.171.26]:25, delay=0.85, delays=0.01/0/0.28/0.56, dsn=2.0.0, status=sent (250 2.0.0 OK 1421032683 p20si20890136qgd.117 - gsmtp)
Jan 11 22:18:03 mydomain-guts postfix/qmgr[3829]: B3E2F1400D9: removed

Best Answer

Ugh how frusterating. I figured it out luckily and carefully examining mail.log is what helped.

What i had to do.

in main.cf I changed the first entry in the mydestination directive to mydomain.com. I had fiddled with after asking and before getting a commend asking for the main.cf file and noticed I was getting different results in mail.log

Finally, I changed

/etc/mailname contains twinsen.mydomain.com.

The problem was the mail was being rejected by my server because of the subdomain name mismatch.