Qmail
[Top] [All Lists]

Re: Route non-local mail

To: tobias carlsson <taddis.ml@gmail.com>
Subject: Re: Route non-local mail
From: Bjorn Jensen <bj@info-connect.dk>
Date: Tue, 19 Dec 2006 16:22:28 +0100
Cc: qmail@list.cr.yp.to
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
In-reply-to: <49512fc70612190520m5b2c8a4dw2fcda7f10112c9c6@mail.gmail.com>
Mailing-list: contact qmail-help@list.cr.yp.to; run by ezmlm
References: <49512fc70612190520m5b2c8a4dw2fcda7f10112c9c6@mail.gmail.com>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Thunderbird/1.5.0.8 Mnenhy/0.7.4.0
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>