1

I want to submit email on port 465 of my smtp server using the Net::SMTP module(without using Net::SMTP::SSL) in a perl script from client. On Port 465 of my SMTP server, "submissions" service runs, which understands SMTPS.

I have tried to find the way to do this on google. Then used the Net::SMTP::SSL module to make request on port 465. It works fine.

But the documentation for Net::SMTP::SSL recommends using latest version Net::SMTP instead of using Net::SMTP::SSL. The document clearly states that

Since Net::SMTP v1.28 (2014-10-08), Net::SMTP itself has support for SMTP over SSL, and also for STARTTLS. Use Net::SMTP, not Net::SMTP::SSL.

I have updated Net::SMTP module to the latest version 3.11.

Also the document for Net::SMTP also stated clearly that

With IO::Socket::SSL installed it also provides support for implicit and explicit TLS encryption, i.e. SMTPS or SMTP+STARTTLS.

The part of my perl script code on client ,relevant to the problem mentioned looks like so:

$smtp = Net::SMTP::SSL->new("$mailserver",
                        Hello => "$localhostname",
                        Timeout => 60,
                        Port => "$port",  //Port value is 465
                        Debug => 1);
 $smtp->auth($username, $password);

...Remaining script which sets sender, receiver body etc

This works fine. The email gets submitted. Replacing the above code with :

$smtp = Net::SMTP->new("$mailserver",
                        Hello => "$localhostname",
                        Timeout => 60,
                        Port => "$port",  //Port value is 465
                        Debug => 1);
$smtp->auth($username, $password);

...Remaining script which sets sender, receiver body etc

This fails. The debug logs look like this:

Net::SMTP>>> Net::SMTP(3.11)
Net::SMTP>>>   Net::Cmd(3.11)
Net::SMTP>>>     Exporter(5.73)
Net::SMTP>>>   IO::Socket::INET(1.39)
Net::SMTP>>>     IO::Socket(1.39)
Net::SMTP>>>       IO::Handle(1.39)
Net::SMTP: Net::Cmd::getline(): unexpected EOF on command channel:  at fescommon/mailsend-new.pl line 67.
Can't call method "auth" on an undefined value at fescommon/mailsend-new.pl line 74.

Note: Modules like Net::SMTP, Net::SMTP::SSL, IO::Socket::SSL and others are all updated to the latest version.

Expected Result is that request on "submissions" service listening on port 465 on SMTP server can be made using latest Net::SMTP module, without using Net::SMTP::SSL (because the document claims)

Stefan Becker
  • 5,695
  • 9
  • 20
  • 30
Ayush
  • 880
  • 1
  • 9
  • 21

1 Answers1

2

If you want to use smtps (i.e. TLS from start instead TLS after the STARTTLS command) you have to explicitly say so. Net::SMTP does not magically derive this requirement from the port number. From the documentation:

new ( [ HOST ] [, OPTIONS ] )
SSL - If the connection should be done from start with SSL, contrary to later upgrade with starttls. You can use SSL arguments as documented in IO::Socket::SSL, but it will usually use the right arguments already.

Thus, the proper code should be:

$smtp = Net::SMTP->new($mailserver,
    SSL => 1,  # <<<<<<<<<<<<<<<<<<<<<<<< THIS IS IMPORTANT
    Hello => $localhostname,
    Timeout => 60,
    Port => $port,  # Port value is 465
    Debug => 1
);
Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • Yes, I myself figured this out a few minutes ago while reading the document. Thanks for your answer sir. – Ayush Mar 29 '19 at 10:01
  • In a linux machine where the version of Net::Cmd is 2.29 , the constructor of Net::SMTP gives undefined object ,though the document says that minimum version required to use SMTPS via Net::SMTP is 1.28. When i updated the Net::Cmd module to version 3.11, then it started working fine. – Ayush Mar 29 '19 at 11:29
  • 1
    @Ayush: The documentation if Net::SMTP::SSL is slightly wrong. 1.28 is the version of libnet where Net::SMTP is part of. You should also use the Net::Cmd coming with this libnet. – Steffen Ullrich Mar 29 '19 at 11:43
  • Sir, on my system , Net::SMTP is v2.31 and Net::Cmd is v2.29. Considering the fact that both of these are part of libnet and correcting the document of Net::SMTP::SSL , we can say that if libnet version is greater than 1.28, then SMTPS feature should work. In my system , i tried finding the version of libnet using the command rpm -q libnet. It says that libnet is not installed. If that is so, then how am I able to use the perl modules like Net::SMTP in my perl script – Ayush Mar 29 '19 at 11:57
  • 1
    @Ayush: libnet 1.28 includes Net::SMTP 2.35 and Net::Cmd 2.31. See https://metacpan.org/source/SHAY/libnet-1.28 – Steffen Ullrich Mar 29 '19 at 12:00