Mailing List Archive

Use relay host in dependency of sender address
Hi,

I can route mails with smtproutes by recipient domains, so that mails to
testdomain.com are routed via a special relay server.

Is there a way to route messages by the sender address, too?
This means, that all messages with the sender address email@mydomain.com
were routed via a special server?

For postfix this is done via "sender_dependent_relayhost_maps"
http://www.postfix.org/postconf.5.html#sender_dependent_relayhost_maps

Is this possible with qmail, too?

Thanks

Stephan
Re: Use relay host in dependency of sender address [ In reply to ]
>Is there a way to route messages by the sender address, too? This
>means, that all messages with the sender address email@mydomain.com
>were routed via a special server?

Yes, but it's kind of a pain to do. You have to set up a separate queue
of some sort for each route.

One way to do it is to set up multiple copies of qmail in
/var/qmail-<whatever>, and put a catchall route in
/var/qmail-whatever/smtproutes. Then in the sender's account arrange
to set QMAILQUEUE to be /var/qmail-whatever/bin/qmail-queue so his
mail is queued there.

A slightly lighter weight approach is to direct the mail you want
routed separately into a maildir, then use maildirserial to move it
from the maildir to the target server. For that I'd write a perl shim
in front of qmail-queue that puts an appropriate prefix in front of
the target address so it goes into the maildir.

If it sounds like qmail wasn't really intended to do this, I wouldn't
disagree.

Regards,
John Levine, johnl@iecc.com, Primary Perpetrator of "The Internet for Dummies",
Information Superhighwayman wanna-be, http://www.johnlevine.com, ex-Mayor
"More Wiener schnitzel, please", said Tom, revealingly.
Re: Use relay host in dependency of sender address [ In reply to ]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday, January 30 at 02:04 PM, quoth John Levine:
>> Is there a way to route messages by the sender address, too? This
>> means, that all messages with the sender address email@mydomain.com
>> were routed via a special server?
>
> Yes, but it's kind of a pain to do. You have to set up a separate queue
> of some sort for each route.

There's *another* way to do it which is even lighter weight, and
doesn't require a separate queue, but only works if all your routing
is going to be to remote domains (i.e. you can't have some mail
delivered locally based on the sender). All you need to do is put a
wrapper around qmail-remote that reads a file similar to smtproutes.
Something like this (you'd need to rename the original qmail-remote
executable to qmail-remote.orig):

#!/bin/sh
configfile=/var/qmail/control/senderroutes
host="$1"
sender="$2"
shift 2
if grep -q "^$sender:" $configfile ; then
host=`awk -F: "/^$sender:/{print \$2}" $configfile`
fi
exec /var/qmail/bin/qmail-remote.orig "$host" "$sender" "$@"

You can, of course, make the searching process more complicated, to
match wildcards, but you get the basic idea.

> If it sounds like qmail wasn't really intended to do this, I
> wouldn't disagree.

Heh, true, but if we limited ourselves to what things were *intended*
for, we'd never get anywhere. I doubt the wheel was *intended* for
automobiles, but it sure works well there. :)

~Kyle
- --
I hope our wisdom will grow with our power, and teach us, that the
less we use our power the greater it will be.
-- Thomas Jefferson
-----BEGIN PGP SIGNATURE-----
Comment: Thank you for using encryption!

iEYEARECAAYFAkmDFJkACgkQBkIOoMqOI17N1wCgnyI+BQJfUcSfSrGuGWvn/AoM
/KsAoOBSWDmmdl3joypJ22gG/DDbcsy5
=uV34
-----END PGP SIGNATURE-----
Re: Use relay host in dependency of sender address [ In reply to ]
On Fri, 2009-01-30 at 13:11 +0100, Stephan Schulze wrote:
> Is there a way to route messages by the sender address, too?
> This means, that all messages with the sender address email@mydomain.com
> were routed via a special server?
>
I have patched qmail for my Mail server IndiMail
(http://www.indimail.org) to use an environment variable SMTPROUTES and
a concept called envrules.
To achieve this I simply would do

email@mydomain.com:SMTPROUTES=:special.relay:25

You can have the following entry in from.envrules

Specific environment variables can be set for specific senders. The
format of this file is of the form pat:envar1=val,envar2=val,...] where
pat is a regular expression which matches a sender. envar1, envar2 are
list of environment variables to be set. If var is omitted, the
environment variable is unset.
The name of the control file can be overriden by the environment
variable FROMRULES

Example:
answerme@save*:DATABYTES=2000000, MAXRECIPIENT=2,QMAILQUEUE=

The above example sets DATABYTES, MAXRECIPIENTS and unsets QMAILQUEUE
if the sender is answerme@saveme.com, answerme@saveabcd.in, etc