3

I'm trying to pipe one specific address to php script but it seems my transport_maps doesn't trigger, instead of it the virtual_transport is used. Here is what I have:

@example.com is listed in virtual_mailbox_domains and the delivery to virtual mailboxes works fine.

But I need to forward all messages for foo@example.com not to dovecot-lda (which is specified in virtual_transport) but to another service.

This is my delivery method for virtual_transport:

dovecot unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/dovecot-lda -f ${sender} -d ${recipient}

This is is where I want to pipe all foo@example.com

php_script unix - n n - - pipe flags=Fq user=www-data argv=/home/script.php

postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
dovecot_destination_recipient_limit = 1
mailbox_size_limit = 0
milter_default_action = accept
milter_protocol = 2
mydestination = localhost
myhostname = localhost
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
non_smtpd_milters = net:localhost:12301
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
smtpd_milters = inet:localhost:12301
smtpd_recipient_restrictions =
smtpd_relay_restrictions = permit_sasl_authenticated permit_mynetworks
defer_unauth_destination smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/ssl/certs/mailserver.pem
smtpd_tls_key_file = /etc/ssl/private/mailserver.pem
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
transport_maps = hash:/etc/postfix/transport
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-
domains.cf virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_transport = dovecot

in /etc/postfix/transport foo@example.com php_script

It seems the postfix just ignore transport_map, I always get User unknown in virtual mailbox table. Which is correct there is no such user, but I want to forward the mail via transport_maps before check if is there virtual user.

Anyone could help? Spend two days searching, reading man and trying but seems it's just doesn't work.

Daniel
  • 403
  • 5
  • 9

3 Answers3

7

Ok I got the solution:

It seems postfix does not work with both virtual_transport and transport_maps so I have created in virual_aliases the forward to foo@localhost and then I use the transport_maps file to pipe foo@localhost to script :)

Daniel
  • 403
  • 5
  • 9
  • 1
    Well done. You should accept your own answer. You made my day. – redochka Sep 18 '15 at 14:16
  • This claim is incorrect. I discovered that when I tried to [play with mailman3 and postfix](http://serverfault.com/questions/733304/getting-mailman3-to-play-nicely-with-postfix-and-dovecot). It's actually the `virtual_mailbox_maps` setting that prevents postfix from consulting the `transport_maps` setting. – Stephan Klein Nov 02 '15 at 19:47
2

My solution, for the record,

Create a specific transport:

# vi /etc/postfix/master.cf
dummy-redirect unix -   n       n       -       50      pipe
    user=vmail argv=/opt/postfix-scripts/redirect.py
    ${sender} ${recipient}

See [http://www.postfix.org/pipe.8.html] for script arguments

Add a map to trigger the transport:

# vi /etc/postfix/redirect_map
plup@dummy.happy-dev.fr   dummy-redirect

# postmap /etc/postfix/redirect_map

Configure the domain and and the transport map:

# vi /etc/postfix/main.cf
virtual_mailbox_domains = dummy.happy-dev.fr
virtual_transport = discard
transport_maps = hash:/etc/postfix/redirect_map

In my case virtual_transport = discard replace the default configuration to keep it consistent.

# service postfix reload

# postconf -d mail_version
mail_version = 2.11.3
Plup
  • 750
  • 1
  • 6
  • 13
0

Yes Daniel was right with ->

It seems postfix does not work with both virtual_transport and transport_maps

But in in my case I disable

#virtual_transport = lmtp:unix:private/dovecot-lmtp

in main.cf

and add in the /etc/postfix/transport file

my-domain1.com      lmtp:unix:private/dovecot-lmtp
my-domain2.com      lmtp:unix:private/dovecot-lmtp
my-domain3.com      lmtp:unix:private/dovecot-lmtp

after this I can use

Postfix transport_maps with virtual_mailbox

###### MySQL Connection ######
virtual_alias_maps = mysql:/etc/postfix/sql/aliases.cf
virtual_mailbox_maps = mysql:/etc/postfix/sql/accounts.cf
virtual_mailbox_domains = mysql:/etc/postfix/sql/domains.cf
local_recipient_maps = $virtual_mailbox_maps  
...
Ingo
  • 5,239
  • 1
  • 30
  • 24