I'm running qmail on my Gentoo box. I wrote a Perl script that runs a query against a MySQL db to get a list of customer email addresses. This script then takes a full email for input and rewrites the 'To' header and sends it with qmail-inject for each email address from the db. I have an alias set up in qmail that pipes anything sent through it into this script that I wrote. This setup works just fine, except when an email address no longer exists. The MTA of the server where the email no longer exists sends the failure notice to alias@<myhost> instead of to <originalsender>@<myhost>. Does anyone know why this is? My script is below.

#!/usr/bin/perl
use DBI();

my $counter = 0;
my @email;
my $dbh = DBI->connect("DBI:mysql:database=<db>;host=<ip>", "<username>", "<password>", {'RaiseError' => 1});
my $query = "SELECT fname, lname, homeemail, officeemail FROM people WHERE current=1";
my $sth = $dbh->prepare($query);
$sth->execute();


@email = <STDIN>;

while(my $ref = $sth->fetchrow_hashref()) {
  if($ref->{homeemail} ne "NULL" && $ref->{homeemail} ne "") {
    open PIPE, "| /var/qmail/bin/qmail-inject $ref->{homeemail}";
    foreach my $line (@email) {
      $line =~ s/^To: .+$/To: \"$ref->{fname} $ref->{lname}\" <$ref->{homeemail}>/;
      print PIPE "$line";
    }
    close PIPE;
  }
  if($ref->{officeemail} ne "NULL" && $ref->{officeemail} ne "") {
    open PIPE, "| /var/qmail/bin/qmail-inject $ref->{officeemail}";
    foreach my $line (@email) {
      $line =~ s/^To: .+$/To: \"$ref->{fname} $ref->{lname}\" <$ref->{officeemail}>/;
      print PIPE "$line";
    }
    close PIPE;
  }
}

$sth->finish();
$dbh->disconnect();

--
Andrew Gaffney


-- [EMAIL PROTECTED] mailing list



Reply via email to