Skip to main content

mac.sandman.net

Piping commands for PostFix in Mac OS X Server

7 May 2007 - Server
133
Piping commands for PostFix in Mac OS X Server
I am writing this in English since I've looked high end low for a solution to this online and now that I have it figured out I thought I'd just post it here for Google to index so it can help others.
Basically, what I wanted to do was to have mail sent to a specific address piped to a perl script. I own the domain "sandman.net" and I wanted mail to "mailinglist@sandman.net" to be piped to my selfbuilt mailinglist manager, which resides, on the server, in path "/Users/sandman/MailExec/list.pl"
Coming from a sendmail background, I have messed around with /etc/mail/virtusertable and /etc/aliases to achieve this, but with postfix (the MTA in OSX) it wasn't as straightforward.
Basically, putting this in /etc/postfix/aliases didn't work:
mailinglist: |/Users/sandman/MailExec/list.pl
And would bounce with "no such mailbox". Doing it the other way, in "/etc/postfix/virtual":
mailinglist@sandman.net "|/Users/sandman/MailExec/list.pl"
Did the same. The solution was to make it a two-step process:
/etc/virtual: mailinglist@sandman.net mailinglist /etc/aliases: mailinglist: "|/Users/sandman/MailExec/list.pl"
So, the virtual user table handles the incoming address and pipes it to the local user "mailinglist", which is piped to the perl script in the aliases file. This is the output of my postconf -n:
alias_maps = hash:/etc/aliases command_directory = /usr/sbin config_directory = /etc/postfix content_filter = smtp-amavis:[127.0.0.1]:10024 daemon_directory = /usr/libexec/postfix debug_peer_level = 2 enable_server_options = yes html_directory = no inet_interfaces = all mail_owner = postfix mailbox_size_limit = 0 mailbox_transport = cyrus mailq_path = /usr/bin/mailq manpage_directory = /usr/share/man maps_rbl_domains = message_size_limit = 0 mydestination = $myhostname,localhost.$mydomain,mail.eklundh.com mydomain = eklundh.com mydomain_fallback = localhost myhostname = mail.eklundh.com mynetworks = 127.0.0.1/32,web.eklundh.com mynetworks_style = host newaliases_path = /usr/bin/newaliases owner_request_special = no queue_directory = /private/var/spool/postfix readme_directory = /usr/share/doc/postfix recipient_delimiter = + relayhost = sample_directory = /usr/share/doc/postfix/examples sendmail_path = /usr/sbin/sendmail setgid_group = postdrop smtpd_client_restrictions = permit_mynetworks reject_rbl_client sbl-xbl.spamhaus.org reject_rbl_client relays.ordb.org permit smtpd_enforce_tls = no smtpd_pw_server_security_options = cram-md5 smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination,permit smtpd_sasl_auth_enable = yes smtpd_tls_cert_file = /etc/certificates/Sandman Mail Service.crt smtpd_tls_key_file = /etc/certificates/Sandman Mail Service.key smtpd_use_pw_server = yes smtpd_use_tls = yes unknown_local_recipient_reject_code = 550 virtual_alias_maps = hash:/etc/postfix/virtual virtual_mailbox_domains = hash:/etc/postfix/virtual_domains virtual_transport = lmtp:unix:/var/imap/socket/lmtp
And after doing any edits to any of these files, issue these commands:
cd /etc/postfix postmap virtual postalias aliases postfix reload
To make the changes active.