On Thu, 23 Apr 2009, Charlie Brady wrote:

On Thu, 23 Apr 2009, J?rg C. Meyer wrote:

 we have the following situation. A mail from a scpecial sender is
 processed and it seems it is forwarded by smtp-forward to the next hop (a
 queueing qmail process on the same host). But it never arrives there,
 qmail-send log is empty and the mail is never delivered to the final
 recipient. Attached is the qpsmtpd log of the mentioned session. Any ideas
 would be much appreciated!

You are not handing the message to qmail, you are handing it to an unspecified SMTP daemon. From looking at your log, that daemon is running on port 125. I'd suggest that you look at the logs of that SMTP daemon.

What smtp-forward plugin are you using? I once diagnosed a problem where the smtp-forward plugin wasn't relaying failed delivery back to the sender:

http://bugs.contribs.org/show_bug.cgi?id=813

I've just looked in git, and I see that the smtp-forward plugin is still the primitive one which makes no attempt to pass status codes back to the originator. This *will* cause you to lose mail.

Allan Joergensen made substantial changes to the plugin to fix that deficiency:

http://www.mail-archive.com/qpsmtpd@perl.org/msg04147.html

His patches are now 404, but I believe I have copies of his code, which I'll append below.

=head1 NAME

smtp-forward

=head1 DESCRIPTION

This plugin forwards the mail via SMTP to a specified server, rather than
delivering the email locally.

=head1 CONFIG

It takes one required parameter, the IP address or hostname to forward to.

  queue/smtp-forward 10.2.2.2

Optionally you can also add a port:

  queue/smtp-forward 10.2.2.2 9025

=cut

use Net::SMTP;

sub register {
  my ($self, $qp, @args) = @_;

  if (@args > 0) {
    if ($args[0] =~ /^([\.\w_-]+)$/) {
      $self->{_smtp_server} = $1;
    }
    else {
      die "Bad data in smtp server: $args[0]";
    }
    $self->{_smtp_port} = 25;
    if (@args > 1 and $args[1] =~ /^(\d+)$/) {
      $self->{_smtp_port} = $1;
    }
$self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if (@args > 2);
  } else {
    die("No SMTP server specified in smtp-forward config");
  }

}

sub hook_queue {
  my ($self, $transaction) = @_;

$self->log(LOGINFO, "forwarding to $self->{_smtp_server}:$self->{_smtp_port}");
  my $smtp = Net::SMTP->new(
                            $self->{_smtp_server},
                            Port => $self->{_smtp_port},
                            Timeout => 60,
                            Hello => $self->qp->config("me"),
                           ) || die $!;
  $smtp->mail( $transaction->sender->address || "" );
  my $rc = $smtp->code;
  my $message = $smtp->message;
  chomp($message);

  if ($rc =~ m/^4\d{2}$/ ) {
        return(DENYSOFT, "Unable to queue message ($message)");
  } elsif ($rc =~ m/^5\d{2}$/ ) {
        return(DENY, "Unable to queue message ($message)");
  }

  for ($transaction->recipients) {
    $smtp->to($_->address);
        $rc = $smtp->code;
        $message = $smtp->message;
        chomp($message);

                if ($rc =~ m/^4\d{2}$/ ) {
return(DENYSOFT, "Unable to queue message ($message)");
                } elsif ($rc =~ m/^5\d{2}$/ ) {
return(DENY, "Unable to queue message ($message)");
                }
  }

  $smtp->data();
  $rc = $smtp->code;
  #$message = $smtp->message;
  chomp($message);

  if ($rc =~ m/^4\d{2}$/ ) {
        return(DENYSOFT, "Unable to queue message ($message)");
  } elsif ($rc =~ m/^5\d{2}$/ ) {
        return(DENY, "Unable to queue message ($message)");
  }

  $smtp->datasend($transaction->header->as_string);
  $rc = $smtp->code;
  $message = $smtp->message;
  chomp($message);


  if ($message =~ m/^End data with/ ) {
        (undef, $message) = split(/:/, $message);
        if ($message) { $message =~ s/^\s//; }
  }

  if ($rc =~ m/^4\d{2}$/ ) {
        return(DENYSOFT, "Unable to queue message ($message)");
  } elsif ($rc =~ m/^5\d{2}$/ ) {
        return(DENY, "Unable to queue message ($message)");
  }

  $transaction->body_resetpos;

  while (my $line = $transaction->body_getline) {
    $smtp->datasend($line);

    $rc = $smtp->code;
    $message = $smtp->message;
    chomp($message);

    if ($message =~ m/^End data with/ ) {
        (undef, $message) = split(/:/, $message);
        if ($message) { $message =~ s/^\s//; }
    }

    if ($rc =~ m/^4\d{2}$/ ) {
        return(DENYSOFT, "Unable to queue message ($message)");
    } elsif ($rc =~ m/^5\d{2}$/ ) {
        return(DENY, "Unable to queue message ($message)");
    }
  }

  $smtp->dataend();
  $rc = $smtp->code;
  $message = $smtp->message;
  my $queue_message;
  chomp($message);

  if ($message =~ m/^End data with/ ) {
        (undef, $message) = split(/\n/, $message);
        if ($message) { $message =~ s/^\s//; }
  }

  if ($rc =~ m/^4\d{2}$/ ) {
        return(DENYSOFT, "Unable to queue message ($message)");
  } elsif ($rc =~ m/^5\d{2}$/ ) {
        return(DENY, "Unable to queue message ($message)");
  } else {
        $queue_message = $message;
  }

  $smtp->quit();
  $rc = $smtp->code;
  $message = $smtp->message;
  chomp($message);

  if ($rc =~ m/^4\d{2}$/ ) {
        return(DENYSOFT, "Unable to queue message ($message)");
  } elsif ($rc =~ m/^5\d{2}$/ ) {
        return(DENY, "Unable to queue message ($message)");
  }

  $self->log(LOGINFO, "finished queueing");
  return (OK, "Queued! ($queue_message)");
}

Reply via email to