简体   繁体   中英

Net::SMTP freezes on a certain server

I have a Perl script for sending Emails:

#!/usr/bin/perl

use strict;
use warnings;

use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP ();
use Email::Simple ();
use Email::Simple::Creator ();

my $smtpserver = 'server.com';
my $smtpport = 2525;
my $smtpuser   = 'test@server.com';
my $smtppassword = 'secret';

my $transport = Email::Sender::Transport::SMTP->new({
  host => $smtpserver,
  port => $smtpport,
  sasl_username => $smtpuser,
  sasl_password => $smtppassword,
  debug => 1,
});

my $email = Email::Simple->create(
  header => [
    To      => 'myself@gmail.com',
    From    => "User name <$smtpuser>",
    Subject => 'Hello',
  ],
  body => "This is my message\n",
);

sendmail($email, { transport => $transport });

It works on one server. But on another the script freezes. Debug messages are:

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)

What's wrong? How to debug?

This happens if the TCP connection to the server was successfully established but the server does not send the expected SMTP greeting back. This can have several reasons, like:

  • The server is not a SMTP server at all. If you try to use Net::SMTP against a web server (eg HTTP) you will see a similar result, because the HTTP server expects the client to send data first whereas with SMTP the server will send data first.
  • The server has implicit TLS configured, that is it is waiting for the client to connect with TLS and not with plain SMTP. In this case the server is waiting for the client to start with the TLS handshake (ie send ClientHello) before sending anything back.

I would suggest you look at the configuration of the server to see what is actually is expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM