1

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.

Halfgaar
  • 7,921
  • 5
  • 42
  • 81
  • 1
    Googling for "postfix tee" brings up a number of hits. This one looks vaguely promising if you scroll down towards the end: http://www.linuxforums.org/forum/servers/160690-postfix-duplicating-mail-two-relayhost.html ... but do check out some of the other hits, too. – tripleee Jun 11 '12 at 05:43

3 Answers3

1

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?

Halfgaar
  • 7,921
  • 5
  • 42
  • 81
1

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 :)

0

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

adamo
  • 6,867
  • 3
  • 29
  • 58
  • 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 08: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 08: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 08:50
  • 1
    There are people who use [milter-archiver](http://code.google.com/p/milter-archiver/) and [milter-bcc](http://www.snertsoft.com/sendmail/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