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;
}
|