On 11/3/2017 6:26 AM, nico...@devels.es wrote:
> El 2017-11-03 11:05, wie...@porcupine.org escribió:
>> Noel Jones:
>>> On 11/2/2017 7:48 AM, nico...@devels.es wrote:
>>> > Hi,
>>> >
>>> > I'm running Postfix 2.9.6 and I'm trying to do a conditional
>>> sender
>>> > rewrite based on recipient address. Machine sends e-mails as
>>> > r...@internal-domain.com by default, but if the recipient is
>>> > u...@external-domain.com I want to rewrite sender to be
>>> > r...@different-domain.com.
>>> >
>>> > To do so, I've tried doing the following:
>>> >
>>> > 1) In master.cnf I added:
>>> >    toext     unix  -       -       n       -       -       smtp -o
>>> > canonical_maps=hash:/etc/postfix/generic_toext
>>
>> Perhaps with smtp_generic_maps, but not with canonical
>> maps because that happens before the queue.
>>
>>     Wietse
> 
> Thank you.
> 
> By now I'm trying to implement a content filter to change some
> headers of the received message. To do that, I added a service to
> the master.cf file:
> 
>   external   unix  -       n       n       -       -       pipe
>     flags=Fq user=user:user argv=/opt/scripts/external.sh ${recipient}
> 
> The script is a very simple bash script that replaces the 'From'
> header:
> 
>     #!/bin/bash
> 
>     content=$(cat)
>     contfin=$(sed 's/From: r...@original-domain.com/From:
> r...@modified-domain.com/' <<< "$content")
> 
>     TMPFILE=`mktemp`
>     echo $contfin > $TMPFILE
> 
>     cat $TMPFILE | /usr/sbin/sendmail -G -i -f
> r...@modified-domain.com -- $1
> 
>     /bin/rm -f $TMPFILE
> 
>     exit $?
> 
> In transports map file (postmapped):
> 
>     destinar...@user.com  external:
> 
> The script seems to do what it should, however, in the Postfix logs
> it seems to loop, like the message was put in the queue again and
> passed to the queue over and over (and the message never arrives):

Yes, it does loop because the transport map will always send the
mail to the 'external' transport.

Two choices to fix this.  The clean way is to setup a second postfix
instance and have your script submit the mail to that second
instance. This clearly separates the mangle and delivery functions
and will be fairly easy to maintain.
http://www.postfix.org/MULTI_INSTANCE_README.html

The other way is to have your script also mangle the envelope
recipient address so the transport table no longer matches.  Then
use smtp_generic_maps to correct the recipient address during delivery.



  -- Noel Jones

Reply via email to