Qmail
[Top] [All Lists]

Re: Route non-local mail

To: qmail@list.cr.yp.to
Subject: Re: Route non-local mail
From: "tobias carlsson" <taddis.ml@gmail.com>
Date: Wed, 20 Dec 2006 08:34:02 +0100
Delivered-to: sp-com-lists@consult.net
Delivered-to: gmail-qmail@securepoint.com
Delivered-to: sp.com.list@gmail.com
Delivered-to: mailing list qmail@list.cr.yp.to
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=ThzCBtnn7wXpxO3orGjw0T7q4onE499Za4DGSsFbCPhVLOS/AOT5bIJANjf/FWNNW20JbUPrGUnuP1hidpXSQQotF0tjAR83KnLVr/GmQejYB5SpgUPKgC4rttfWlLVCuKpu6ESrF/ITXzsp2TEnstu+ORN8F/Rncqm6II3AnKE=
Domainkey-status: good (test mode)
In-reply-to: <458803B4.404@info-connect.dk>
Mailing-list: contact qmail-help@list.cr.yp.to; run by ezmlm
References: <49512fc70612190520m5b2c8a4dw2fcda7f10112c9c6@mail.gmail.com> <458803B4.404@info-connect.dk>
Hi,

I looked at the solution Charles suggested and the .qmail based script you supplied and the script solution was great! I have alot of account on server1 and I really didn't want to change  the setup  that much on server1 just to get a few mailman accounts going on server2.

Thanks for that script solution Bjorn.

Best regards
Tobias Carlsson

On 12/19/06, Bjorn Jensen < bj@info-connect.dk> wrote:
tobias carlsson wrote:
> Hi,
>
> I'm trying to figure out how to route non-local mails for a certain
> domain
> to a second server that handles the same domain.
> I know that I can put user@system2.domain.com in a forward.. but is
> there a
> way to get qmail to understand that I want it
> sent to the second MX automagically when its not local and without
> changing
> the address?
> I really dont want it to change the adress from user@domain.com to
> user@system2.domain.com to get to the other system.
> Maybe that's impossible to achieve?
I've created the attached script to accomplish this from within .qmail
files because I needed certain things to happen before routing emails on
to another server. It's perl and can surely be optimized, but it still
works great for me.

I call it from .qmail like so:
| /var/qmail/bin/qmail- remote-invoke.pl new.server.dom "$SENDER"
"$EXT@$HOST"

Regards,
Bjorn Jensen


#!/usr/bin/perl

$argslen = scalar @ARGV;

if ($argslen != 3){
        print "qmail-remote-invoke.pl must be called as: qmail-remote-invoke.pl host sender recip";
        exit 111;
}


@email = <STDIN>;
$file = "/tmp/".generate_random_string(11);

open(tmpfile, ">>$file");

foreach $line (@email){
        print tmpfile $line;
}

close(tmpfile);

$sender =~ s/["]//g;

$status = `/var/qmail/bin/qmail-remote $ARGV[0] "$sender" "$ARGV[2]" < $file`;

$del = `rm -f $file`;

$status =~ s/[^\p{IsPrint}\s]//g;

$first = substr($status, 0, 1);
$second = substr($status, 1, 1);

$rest = $status;

print "$rest\n";
if ($first eq "r" or $first eq "K"){
        exit 0;
} elsif ($first eq "h" or $first eq "D") {
        exit 100;
} else {
        exit 111;
}

sub generate_random_string
{
        my $length_of_randomstring=shift;#the length of the random string to generate

        my @chars=('q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','0','1','2','3','4','5','6','7','8','9','_');
        my $random_string;
        foreach (1..$length_of_randomstring)
        {
                #rand @chars will generate a random number between 0 and scalar @chars
                $random_string.=$chars[rand @chars];
        }
        return $random_string;
}


<Prev in Thread] Current Thread [Next in Thread>