1

We are using Perl 5, version 18, subversion 1 (v5.18.1) built.

Earlier we were connecting outlook 2007 to connect through Mail::IMAPClient Module using user and password as it wasn't required to use SSL or TLS. Now we have migrated outlook to 2016, and in this version is necessary to introduce SSL or TLS.

I have tried to add SSL code in the Perl script, and it's failing as below:

Can't locate object method "new" via package "IO::Socket::SSL" (perhaps you forgot to load "IO::Socket::SSL"?)


My code:

$client = Mail::IMAPClient->new(
   server   => $Eserver,
   User     => $Euser,
   Password => $Epassword,
   ssl      => 1,
   port     => 993,
   Socket   => IO::Socket::SSL->new
   (  Proto    => 'tcp',
      PeerAddr => $Eserver,
      PeerPort => 993, # IMAP over SSL standard port
   ),

Can someone please help if its right way to add the ssl module in IMAP client. Is it required to upgrade Perl 5 to the latest to use SSL or TLS (using starttls method?).

Also, how can we know which IMAPclient module we are using?

I'm sure something is missing. Not sure as I am naive in working in Perl.

Dave Cross
  • 68,119
  • 3
  • 51
  • 97
Deepak
  • 11
  • 2

2 Answers2

5

Can't locate object method "new" via package "IO::Socket::SSL" (perhaps you forgot to load "IO::Socket::SSL")

Did you forget to load IO::Socket::SSL?

use IO::Socket::SSL;

It's even there in the example in the documentation:

use IO::Socket::SSL;
my $imap = Mail::IMAPClient->new
 ( User     => 'your-username',
   Password => 'your-password',
   Socket   => IO::Socket::SSL->new
   (  Proto    => 'tcp',
      PeerAddr => 'some.imap.server',
      PeerPort => 993, # IMAP over SSL standard port
   ),
);
Dave Cross
  • 68,119
  • 3
  • 51
  • 97
  • This Dave, thanks for your input, I have mentioned the same in the perl script however its still giving error as below , – Deepak Nov 07 '19 at 09:39
  • @Deepak: You might want to double-check the spelling of your `use` line. That error usually means the module is not loaded. Please cut and paste (don't retype) the line from your code into your question. – Dave Cross Nov 07 '19 at 10:02
3

Usually, this means that you forgot line with "use PackageName;"

$ perl -le "IO::Socket::SSL->new()"
Can't locate object method "new" via package "IO::Socket::SSL" (perhaps you forgot to load "IO::Socket::SSL"?) at -e line 1.

and without error

$ perl -le "use IO::Socket::SSL; IO::Socket::SSL->new()"
T'East
  • 79
  • 1
  • 3