user4035
user4035

Reputation: 23749

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   = '[email protected]';
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      => '[email protected]',
    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?

Upvotes: 0

Views: 172

Answers (1)

Steffen Ullrich
Steffen Ullrich

Reputation: 123461

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 (e.g. 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 (i.e send ClientHello) before sending anything back.

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

Upvotes: 2

Related Questions