Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Bug in GT::Mail::Send::sendmail?

Quote Reply
Bug in GT::Mail::Send::sendmail?
Hi,

in Links 3.2.0 I added a Reply-To with a foreign address to an e-mail template and got an postfix error.

The template:
Code:
From: support@mydomain.de>
Subject: Test
To: name@gmx.net
Reply-To: name@web.de
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
Mime-Version: 1.0

Text

The error:
Code:
<name@gmx.net>: host mx1.gmx.net[213.165.64.102] said: 550-5.7.1 {mx076}
The recipient does not accept mails from 'web.de' over foreign mailservers
550 5.7.1 ( http://portal.gmx.net/serverrules ) (in reply to RCPT TO
command)

This is because the return-path is set to reply-to if exists and the sender in the envelope is set to return-path. I changed GT::Mail::Send::sendmail as follows:

Code:
sub sendmail {
# ---------------------------------------------------------------
# Sends a message using sendmail.
#
my $self = shift;

ref $self or $self = $self->new(@_);

# Get a filehandle, and open pipe to sendmail.
my $s = \do{ local *FH; *FH };

# If the email address is safe, we set the envelope via -f so bounces are handled properly.
# [MOD START]
# my $from = $self->{mail}->{head}->get('return-path') || $self->{mail}->{head}->get('from');
my $from = $self->{mail}->{head}->get('reply-to') ? $self->{mail}->{head}->get('from') : $self->{mail}->{head}->get('return-path') || $self->{mail}->{head}->get('from');
# [MOD END]
my $envelope = '';
if ($from =~ /<?([\w\-\.]+\@[\w\-\.]+)>?/) {
$envelope = "-f $1";
}
elsif ($from eq '<>' or $from eq '') {
$envelope = "-f ''";
}
open($s, "|$self->{path} $self->{flags} $envelope 1>&2") or return $self->error("SENDMAIL", "WARN", "$!");
$self->{mail}->write($s);
return 1 if close $s;
my $exit_value = $? >> 8;

my $code;
if (exists $SENDMAIL_ERRORS{$exit_value}) {
$code = $SENDMAIL_ERRORS{$exit_value};
}
else {
$code = 'EX_UNKNOWN';
}
if ($code eq 'EX_TEMPFAIL') {
return 1;
}
return $self->error($code, "WARN", $exit_value);
return 1;
}

Now it works as expected.