How to pipe incoming mail into local script

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
Post Reply
Zuser
Posts: 17
Joined: Wed Sep 14, 2016 3:54 pm
ZCS/ZD Version: 8.8.x

How to pipe incoming mail into local script

Post by Zuser »

Hi,

if I have a Zimbra mail server called "zimbra.example.com" which hosts "example.com" and receives mail to foo@example.com,
what is the correct way of forwarding such mail to a local script?

I've looked at putting

Code: Select all

foo: "|/opt/test.rb"
in /etc/aliases, but that's for local addresses only AFAIK.
Zuser
Posts: 17
Joined: Wed Sep 14, 2016 3:54 pm
ZCS/ZD Version: 8.8.x

Re: How to pipe incoming mail into local script

Post by Zuser »

In the meantime I think I found the right way, but unfortunately it still doesn't work, can anyone point out what I'm doing wrong?

added mailbox foo@example.com in Zimbra
added the following line in /opt/zimbra/postfix/conf/master.cf.in just above the maildrop line:
my_transport unix - n n - - pipe flags=Rq user=zimbra argv=/opt/test.rb --some arguments -a blah

added the following line in /opt/zimbra/postfix/conf/transport:
/^foo@example.com$/ my_transport:dummy

Checked and activated the transport map with:
$ /opt/zimbra/postfix/sbin/postmap -q foo@example.com regexp:/opt/zimbra/postfix/conf/transport
$ sudo /opt/zimbra/postfix/sbin/postmap /opt/zimbra/postfix/conf/transport

Became zimbra user and restarted the mta:
$ sudo su - zimbra
$ zmmtactl reload

This reported it rewrote the postfix config as well and indeed master.cf has been rewritten to include the my_transport line.
Sending mail to foo@example.com still delivers it into the account's mailbox though instead of piping it into the script.
Zuser
Posts: 17
Joined: Wed Sep 14, 2016 3:54 pm
ZCS/ZD Version: 8.8.x

Re: How to pipe incoming mail into local script

Post by Zuser »

Solved:
/opt/zimbra/postfix/conf/main.cf has:
transport_maps = proxy:ldap:/opt/zimbra/conf/ldap-transport.cf, lmdb:/opt/zimbra/postfix/conf/transport

ldap-transport.cf appears to take precedence, so changing the given account's zimbraMailTransport uses the transport I have defined (zmprov ma foo@example.com zimbraMailTransport my_transport:dummy).
Post Reply