Using postfix, I'd like all incoming mail, to any address (including those that don't map to local users) to be piped to a script. I've tried configuring mailbox_command
in /etc/postfix/main.cf
:
mailbox_command = /path/to/myscript.py
This works great if the user is a local user, but it fails for "unknown" users who don't have aliases. I tried setting luser_relay
to a local user, but this pre-empts mailbox_command
, and so the command doesn't get run. I tried setting local_recipient_maps=
(empty string), but the message is still bounced (unknown user).
Is there a magic invocation I can use to get all known and unknown users to go to the script as well?
Full /etc/postfix/main.cf
follows — it's the default Ubuntu 10.04, with the exception of the mailbox_command
line:
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
myhostname = ... snip ...
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = sassafras, ... snip ...,localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
mailbox_command = /path/to/my/script.py
Best Answer
Ok, I just got this working -- though hairier than I thought it would be. I dropped the
maildir_command
part, and went withtransport_maps
. The key is to do 5 things:/etc/postfix/master.cf
to pipe mail to the script./etc/postfix/main.cf
to use the transport db fortransport_maps
, and the alias db forvirtual_alias-maps
.(1) Create
/etc/postfix/virtual_aliases
to add a catch-all alias --localuser
needs to be an existing local user:(2) Create
/etc/postfix/transport
to add a transport mapping. "mytransportname" can be whatever you want; it's used below inmaster.cf
:(3) Next, both
transport
andvirtual_aliases
need to be compiled into berkeley db files:(4) Add the transport to
/etc/postfix/master.cf
:(5) In
/etc/postfix/main.cf
:And... good to go! Sheesh.