Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like a Postfix server to deliver each message to a certain transport as well as relay to a second server. In master.cf, I have the following transport:

zarafa unix - n n - 10 pipe
  flags= user=vmail argv=/usr/bin/zarafa-dagent ${user}

Because I can't get Postfix to deliver to two transports, what I probably need, is a wrapper transport, using procmail maybe, that delivers to zarafa-dagent and relays to a second server (not just forward to an address; relay to a second server).

It can also be a script that calls sendmail or whatever, but at the moment, I don't know how to proceed.

things like bcc_maps don't work, because then it doesn't produce corrent X-Original-To and Delivered-To headers. It needs to be sent to the same recipient on the the server it's being relayed to as the original server.

Edit: maybe I should clarify something: on the backup machine, I can't have the same mailboxes as the primary; there's just one box. If I did have all the mailboxes, a BCC to that server would be fine. But because on the primary, e-mail is delivered using custom zarafa transport, there is no way I can let the secondary know what mailboxes there are. Hence I wanted to relay to that server, and that server also considers itself local for the domain in question. That way, Delivered-To header would tell me what the original RCTP to was.

share|improve this question
1  
Googling for "postfix tee" brings up a number of hits. This one looks vaguely promising if you scroll down towards the end: linuxforums.org/forum/servers/… ... but do check out some of the other hits, too. –  tripleee Jun 11 '12 at 5:43

3 Answers 3

With the help this page, I think I'm almost there, but not yet. I don't know how to relay to the second server yet, from bash.

I made a transport in master.cf:

filtertest    unix  -       n       n       -       10      pipe
    flags=Rq user=filter null_sender=
    argv=/usr/local/bin/filter-test.sh -f ${sender} -- ${recipient}

I included the content_filter option to the smtp transport (will add it to smtps too when it works):

smtp      inet  n       -       -       -       -       smtpd
    -o content_filter=filtertest:dummy

I have the filtertest script:

#!/bin/bash

# Simple shell-based filter. It is meant to be invoked as follows:
#       /path/to/script -f sender recipients...

# Localize these. The -G option does nothing before Postfix 2.3.
INSPECT_DIR=/var/spool/filter
SENDMAIL="/usr/sbin/sendmail -G -i" # NEVER NEVER NEVER use "-t" here.

# Exit codes from <sysexits.h>
EX_TEMPFAIL=75
EX_UNAVAILABLE=69

# Clean up when done or when aborting.
trap "rm -f in.$$" 0 1 2 3 15

# Start processing.
cd $INSPECT_DIR || {
    echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }

cat >in.$$ || {
    echo Cannot save mail to file; exit $EX_TEMPFAIL; }

# Relay message to backup server
#TODO: how?

$SENDMAIL "$@" <in.$$

exit $?

What remains is: how do I make this bash script relay (not forward) the contents of the tmp file to a second server?

share|improve this answer

You can try and use roundhouse or install MIMEDefang and use add_recipient to relay emails to any other server you want.

share|improve this answer
    
Add_recipient suggests it doesn't work for me, because then it doesn't produce corrent X-Original-To and Delivered-To headers. It needs to be sent to the same recipient on the the server it's being relayed to as the original server. –  Halfgaar Jun 18 '12 at 8:09
    
Actually if you take the time and read about MIMEDefang you will see that you it can do what you want, just like Roundhouse does. The recipient is never the "same" in the second server. You have to define "sameness". Do you want it to be the same left hand side? Then add_recipient may work for you. Do you want it to be exactly the same? Do you want this for debugging or for archiving reasons? –  adamo Jun 18 '12 at 8:29
    
I was kind of short, sorry, I will read more about it (I needed to have this finished two weeks ago... :( ). Anyway, why would the recipient not be the same? I just have a bunch of text (headers+body) that needs to be delivered to john@domain.com on server A and B. It's for last-resort backup purposes; mail to all users of domain.com will be stored in an archive maildir, with proper Delivered-To header so I can redliver with fetchmail. –  Halfgaar Jun 18 '12 at 8:50
1  
There are people who use milter-archiver and milter-bcc for that. If I was not time pressed (like you are now) I would attempt to implement this via MIMEDefang. Depending your particular setup needs you may need to write your own milter. –  adamo Jun 18 '12 at 10:00
    
I see that that milter-archiver is a replacement for bcc_maps, but maybe I should clarify something: on the backup machine, I can't have the same mailboxes as the primary; there's just one box. If I did have all the mailboxes, a BCC to that server would be fine. But because on the primary, e-mail is delivered using custom zarafa transport, there is no way I can let the secondary know what mailboxes there are. Hence I wanted to relay to that server, and that server also considers itself local for the domain in question. That way, Delivered-To header would tell me what the original RCTP to was. –  Halfgaar Jun 18 '12 at 12:25

I needed to do something similar, and about your question it really seems postfix doesn't allow for more than one delivery at a time.
The way I managed to solve my problem is to use a little wrapper to catch the request and then run the needed dispatches.
The only problem with it is that postfix will say "Okay, delivered!", but it doesn't really knows if the delivery has been successful or not.
Anyway, this is my wrapper's code:

#!/bin/bash
USER=`echo $2 | awk -F"@" '{print $1}'`
NEXTHOP=`echo $2 | awk -F"@" '{print $2}'`
/usr/bin/sudo -u vmail /usr/bin/procmail -t -m USER=$USER NEXTHOP=$NEXTHOP /etc/procmailrc

"USER" is the username contained into the email, "NEXTHOP" is the domain contained into the email... to be clear: USER@NEXTHOP.

The message would then be passed as stdin to the script, allowing you to fetch it and to use at your own discreption.

I just hope it would be useful to you :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.