git-send-email.perl: improve error message in send_message()
PATCH 1/1 git-send-email.perl: improve error message in send_message()
--- git-send-email.perl | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
git-send-email.perl +4 -1
@@ -957,7 +957,10 @@ X-Mailer: git-send-email $gitversion } if (!$smtp) { - die "Unable to initialize SMTP properly. Is there something wrong with your config?"; + die "Unable to initialize SMTP properly. Check config. ", + "VALUES: server=$smtp_server ", + "encryption=$smtp_encryption ", + defined $smtp_server_port ? "port=$smtp_server_port" : ""; } if (defined $smtp_authuser) {
Signature · 1 line
1.7.0
PATCH 1/1 git-send-email.perl: add option --smtp-debug
--- git-send-email.perl | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
This patch makes it possible to see what's really going on instead of reading a cryptic message like "Unable to initialize SMTP properly".
An example:
$ git send-email --smtp-debug 1 ...
Net::SMTP>>> Net::SMTP(2.31)Net::SMTP>>> Net::Cmd(2.29)Net::SMTP>>> Exporter(5.63)Net::SMTP>>> IO::Socket::INET(1.31)Net::SMTP>>> IO::Socket(1.31)Net::SMTP>>> IO::Handle(1.28)
Net::SMTP=GLOB(0x267ec28)<<< 220 picasso.cante.net ESMTP Exim 4.71 Fri, 12 Mar 2010 23:49:15 +0200 Net::SMTP=GLOB(0x267ec28)>>> EHLO localhost.localdomain Net::SMTP=GLOB(0x267ec28)<<< 550 EHLO argument does not match calling host Net::SMTP=GLOB(0x267ec28)>>> HELO localhost.localdomain Net::SMTP=GLOB(0x267ec28)<<< 550 HELO argument does not match calling host
git-send-email.perl +6 -1
@@ -64,6 +64,7 @@ git send-email [options] <file | directory | rev-list options > --smtp-pass <str> * Password for SMTP-AUTH; not necessary. --smtp-encryption <str> * tls or ssl; anything else disables. --smtp-ssl * Deprecated. Use '--smtp-encryption ssl'. + --smtp-debug <0|1> * Disable, enable Net::SMTP debug. Automating: --identity <str> * Use the sendemail.<id> options.
@@ -187,6 +188,8 @@ my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts); my ($validate, $confirm); my (@suppress_cc); +my ($debug_net_smtp) = 0; # Net::SMTP, see send_message() + my $not_set_by_user = "true but not set by the user"; my %config_bool_settings = (
@@ -270,6 +273,7 @@ my $rc = GetOptions("sender|from=s" => \$sender, "smtp-pass:s" => \$smtp_authpass, "smtp-ssl" => sub { $smtp_encryption = 'ssl' }, "smtp-encryption=s" => \$smtp_encryption, + "smtp-debug:i" => \$debug_net_smtp, "identity=s" => \$identity, "annotate" => \$annotate, "compose" => \$compose,
@@ -938,7 +942,8 @@ X-Mailer: git-send-email $gitversion require Net::SMTP; $smtp ||= Net::SMTP->new((defined $smtp_server_port) ? "$smtp_server:$smtp_server_port" - : $smtp_server); + : $smtp_server, + Debug => $debug_net_smtp); if ($smtp_encryption eq 'tls' && $smtp) { require Net::SMTP::SSL; $smtp->command('STARTTLS');
Signature · 1 line
1.7.0
PATCH 1/1 git-send-email.perl - Fix 550 EHLO argument does not match calling host
Add new function maildomain() which returns FQDN for use in send_message(). The value is passed to Net::SMTP HELO/EHLO handshake.
The default value in Net::SMTP may not get through:
Net::SMTP=GLOB(0x267ec28)>>> EHLO localhost.localdomain Net::SMTP=GLOB(0x267ec28)<<< 550 EHLO argument does not match calling host
whereas using the FQDN, the result is:
Net::SMTP=GLOB(0x15b8e80)>>> EHLO host.example.com Net::SMTP=GLOB(0x15b8e80)<<< 250-host.example.com Hello host.example.com [192.168.1.7]
--- git-send-email.perl | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 50 insertions(+), 2 deletions(-)
This patch is applied *after* the other 2 sent in this thread.
git-send-email.perl +50 -2
@@ -834,6 +834,46 @@ sub sanitize_address } +# Returns the local Fully Qualified Domain Name (FQDN) if available, +# If this is not given to EHLO, the receiving SMTP may deny connection +# Here is an example of Net::SMTP without explicit Helo: it +# uses by default "localhost.localdomain" +# +# Net::SMTP=GLOB(0x267ec28)>>> EHLO localhost.localdomain +# Net::SMTP=GLOB(0x267ec28)<<< 550 EHLO argument does not match calling host + +sub maildomain () +{ + my $maildomain; + eval "use Net::Domain"; + + unless ( $@ ) { + for my $host ( qw(mailhost localhost) ) { + my $smtp = Net::SMTP->new($host); + if (defined $smtp) { + my $domain = $smtp->domain; + $smtp->quit; + + $maildomain = $domain + unless $^O eq 'darwin' && $domain =~ /\.local$/; + + last if $maildomain; + } + } + } + + unless ($maildomain) { + eval "use Net::Domain"; + unless ( $@ ) { + my $domain = Net::Domain::domainname(); + $maildomain = $domain + unless $^O eq 'darwin' && $domain =~ /\.local$/; + } + } + + $maildomain; +} + # Returns 1 if the message was sent, and 0 otherwise. # In actuality, the whole program dies when there # is an error sending a message.
@@ -917,6 +957,8 @@ X-Mailer: git-send-email $gitversion } } + my $maildomain; + if ($dry_run) { # We don't want to send the email. } elsif ($smtp_server =~ m#^/#) {
@@ -936,13 +978,18 @@ X-Mailer: git-send-email $gitversion if ($smtp_encryption eq 'ssl') { $smtp_server_port ||= 465; # ssmtp require Net::SMTP::SSL; - $smtp ||= Net::SMTP::SSL->new($smtp_server, Port => $smtp_server_port); + $maildomain = maildomain() || "localhost.localdomain"; + $smtp ||= Net::SMTP::SSL->new($smtp_server, + Hello => $maildomain, + Port => $smtp_server_port); } else { require Net::SMTP; + $maildomain = maildomain() || "localhost.localdomain"; $smtp ||= Net::SMTP->new((defined $smtp_server_port) ? "$smtp_server:$smtp_server_port" : $smtp_server, + Hello => $maildomain, Debug => $debug_net_smtp); if ($smtp_encryption eq 'tls' && $smtp) { require Net::SMTP::SSL;
@@ -962,9 +1009,10 @@ X-Mailer: git-send-email $gitversion } if (!$smtp) { - die "Unable to initialize SMTP properly. Check config. ", + die "Unable to initialize SMTP properly. Check config and use --smtp-debug. ", "VALUES: server=$smtp_server ", "encryption=$smtp_encryption ", + "maildomain=$maildomain", defined $smtp_server_port ? "port=$smtp_server_port" : ""; }
Signature · 1 line
1.7.0