Hello,
The problem is not related to the module itself, but to some incompatibilities between new versions of other modules.
Workarounds:
1) I solved the issue, with a downgrade of Net::SMTPS to v0.04 (instead of 0.06). It's attached.
Net::SMTPS>>> Net::SMTPS(0.04)
Net::SMTPS>>> IO::Socket::INET6(2.72)
Net::SMTPS>>> IO::Socket(1.38)
Net::SMTPS>>> IO::Handle(1.35)
Net::SMTPS>>> Exporter(5.72)
Net::SMTPS>>> Net::SMTP(3.05)
Net::SMTPS>>> Net::Cmd(3.05)
Net::SMTPS>>> IO::Socket::IP(0.37)
Net::SMTPS=GLOB(0x1aa6eb0)<<< 220 smtp.gmail.com ESMTP g190sm1157682lfe.11 - gsmtp
2) On another machine, I solved the issue just upgrading Net::SMTP to 3.05
Net::SMTPS>>> Net::SMTPS(0.06)
Net::SMTPS>>> IO::Socket::IP(0.37)
Net::SMTPS>>> IO::Socket(1.38)
Net::SMTPS>>> IO::Handle(1.35)
Net::SMTPS>>> Exporter(5.72)
Net::SMTPS>>> Net::SMTP(3.05)
Net::SMTPS>>> Net::Cmd(3.05)
Hope this helps
On Fri Jun 23 02:23:37 2017, lionel.u.l@gmail.com wrote:
Show quoted text> Hi!
>
> I'm using Email::Send::SMTP::Gmail for a Catalyst app. Currently testing
> it, actually. I've used the following code and got this "Can't locate
> object method "send" via package "-1" (perhaps you forgot to load
> "-1"?)" error.
> I've read it is sort of a default error so I used debug and verbose.
>
> *The code is fairly similar to the one in the documentation:*
>
> my ($mail,$error) = Email::Send::SMTP::Gmail->new(
> -smtp => 'smtp.gmail.com',
> -login => $smtp_user,
> -pass => $smtp_pass,
> -verbose => 1,
> -debug => 1
> );
> print "session error: $error" unless ($mail!=-1);
>
> $mail->send(-to=>'lionel.u.l@gmail.com', -subject=>'Hello!',
> -body=>'Just testing it<br>Bye!',-contenttype=>'text/html');
> $mail->bye;
>
>
> *The debug log and the error:*
>
> Connecting to smtp.gmail.com using tls with LOGIN on port 25 and timeout of
> 60
> Net::SMTPS>>> Net::SMTPS(0.06)
> Net::SMTPS>>> IO::Socket::INET6(2.71)
> Net::SMTPS>>> IO::Socket(1.36)
> Net::SMTPS>>> IO::Handle(1.34)
> Net::SMTPS>>> Exporter(5.72)
> Net::SMTPS>>> Net::SMTP(2.31)
> Net::SMTPS>>> Net::Cmd(2.29)
> Net::SMTPS>>> IO::Socket::INET(1.33)
> Net::SMTPS=GLOB(0x6b49008)<<< 220 smtp.gmail.com ESMTP n35sm3006680qta.15 -
> gsmtp
> Net::SMTPS=GLOB(0x6b49008)>>> EHLO localhost.localdomain
> Net::SMTPS=GLOB(0x6b49008)<<< 250-smtp.gmail.com at your service,
> [190.18.121.32]
> Net::SMTPS=GLOB(0x6b49008)<<< 250-SIZE 35882577
> Net::SMTPS=GLOB(0x6b49008)<<< 250-8BITMIME
> Net::SMTPS=GLOB(0x6b49008)<<< 250-STARTTLS
> Net::SMTPS=GLOB(0x6b49008)<<< 250-ENHANCEDSTATUSCODES
> Net::SMTPS=GLOB(0x6b49008)<<< 250-PIPELINING
> Net::SMTPS=GLOB(0x6b49008)<<< 250-CHUNKING
> Net::SMTPS=GLOB(0x6b49008)<<< 250 SMTPUTF8
> Net::SMTPS=GLOB(0x6b49008)>>> my favorite: LOGIN
> Authentication (SMTP) failed
>
> Note that login information provided in $smtp_user and $smtp_pass is
> correct. Also tried forcing all three ports for gmail. Didn't work either.
>
> Any workaround this?
> Thanks!
>
# ====
# SSL/STARTTLS extention for G.Barr's Net::SMTP.
# plus, enable arbitrary SMTP auth mechanism selection.
# IO::Socket::SSL (also Net::SSLeay openssl),
# Authen::SASL, MIME::Base64 should be installed.
#
package Net::SMTPS;
use vars qw ( $VERSION @ISA );
$VERSION = "0.04";
use base qw ( Net::SMTP );
use Net::Cmd; # import CMD_OK, CMD_MORE, ...
use Net::Config;
eval {
require IO::Socket::INET6
and unshift @ISA, 'IO::Socket::INET6';
} or do {
require IO::Socket::INET
and unshift @ISA, 'IO::Socket::INET';
};
use strict;
# Override to support SSL/TLS.
sub new {
my $self = shift;
my $type = ref($self) || $self;
my ($host, %arg);
if (@_ % 2) {
$host = shift;
%arg = @_;
}
else {
%arg = @_;
$host = delete $arg{Host};
}
my $ssl = delete $arg{doSSL};
my $hosts = defined $host ? $host : $NetConfig{smtp_hosts};
my $obj;
# eliminate IO::Socket::SSL from @ISA for multiple call of new.
@ISA = grep { !/IO::Socket::SSL/ } @ISA;
my %_args = map { +"$_" => $arg{$_} } grep {! /^SSL/} keys %arg;
my $h;
$_args{PeerPort} = $_args{Port} || 'smtp(25)';
$_args{Proto} = 'tcp';
$_args{Timeout} = defined $_args{Timeout} ? $_args{Timeout} : 120;
foreach $h (@{ref($hosts) ? $hosts : [$hosts]}) {
$_args{PeerAddr} = ($host = $h);
#if ($_args{Debug}) {
# foreach my $i (keys %_args) {
# print STDERR "$type>>> arg $i: $_args{$i}\n";
# }
#}
$obj = $type->SUPER::new(
%_args
)
and last;
}
return undef
unless defined $obj;
$obj->autoflush(1);
$obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
# common in SSL
my %ssl_args;
if ($ssl) {
eval {
require IO::Socket::SSL;
} or do {
$obj->set_status(500, ["Need working IO::Socket::SSL"]);
$obj->close;
return undef;
};
%ssl_args = map { +"$_" => $arg{$_} } grep {/^SSL/} keys %arg;
$IO::Socket::SSL::DEBUG = (exists $arg{Debug} ? $arg{Debug} : undef);
}
# OverSSL
if (defined($ssl) && $ssl =~ /ssl/i) {
$obj->ssl_start(\%ssl_args)
or do {
$obj->set_status(500, ["Cannot start SSL"]);
$obj->close;
return undef;
};
}
unless ($obj->response() == CMD_OK) {
$obj->close();
return undef;
}
${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses};
${*$obj}{'net_smtp_host'} = $host;
(${*$obj}{'net_smtp_banner'}) = $obj->message;
(${*$obj}{'net_smtp_domain'}) = $obj->message =~ /\A\s*(\S+)/;
unless ($obj->hello($arg{Hello} || "")) {
$obj->close();
return undef;
}
# STARTTLS
if (defined($ssl) && $ssl =~ /starttls/i && $obj->supports('STARTTLS') ) {
(($obj->command('STARTTLS')->response() == CMD_OK)
and $obj->ssl_start(\%ssl_args)
and $obj->hello($arg{Hello} || ""))
or do {
$obj->set_status(500, ["Cannot start SSL session"]);
$obj->close();
return undef;
};
}
$obj;
}
sub ssl_start {
my ($self, $args) = @_;
my $type = ref($self);
(unshift @ISA, 'IO::Socket::SSL'
and IO::Socket::SSL->start_SSL($self, %$args)
and $self->isa('IO::Socket::SSL')
and bless $self, $type # re-bless 'cause IO::Socket::SSL blesses himself.
) or return undef;
}
# Override to specify a certain auth mechanism.
sub auth {
my ($self, $username, $password, $mech) = @_;
eval {
require MIME::Base64;
require Authen::SASL;
} or $self->set_status(500, ["Need MIME::Base64 and Authen::SASL todo auth"]), return 0;
my $mechanisms = $self->supports('AUTH', 500, ["Command unknown: 'AUTH'"]);
if ($mech) {
$mechanisms = $mech;
}
return unless $mechanisms;
my $sasl;
if (ref($username) and UNIVERSAL::isa($username, 'Authen::SASL')) {
$sasl = $username;
$sasl->mechanism($mechanisms);
}
else {
die "auth(username, password)" if not length $username;
$sasl = Authen::SASL->new(
mechanism => $mechanisms,
callback => {
user => $username,
pass => $password,
authname => $username,
}
);
}
# We should probably allow the user to pass the host, but I don't
# currently know and SASL mechanisms that are used by smtp that need it
my $client = $sasl->client_new('smtp', ${*$self}{'net_smtp_host'}, 0);
my $str = $client->client_start;
# We dont support sasl mechanisms that encrypt the socket traffic.
# todo that we would really need to change the ISA hierarchy
# so we dont inherit from IO::Socket, but instead hold it in an attribute
my @cmd = ("AUTH", $client->mechanism);
my $code;
push @cmd, MIME::Base64::encode_base64($str, '')
if defined $str and length $str;
while (($code = $self->command(@cmd)->response()) == CMD_MORE) {
@cmd = (
MIME::Base64::encode_base64(
$client->client_step(MIME::Base64::decode_base64(($self->message)[0])), ''
)
);
}
$code == CMD_OK;
}
1;
__END__
=head1 NAME
Net::SMTPS - SSL/STARTTLS support for Net::SMTP
=head1 SYNOPSYS
use Net::SMTPS;
my $ssl = 'starttls'; # 'ssl' / 'starttls' / undef
my $smtp = Net::SMTPS->new("smtp.example.com", Port => 587, doSSL => $ssl);
=head1 DESCRIPTION
This module implements a wrapper for Net::SMTP, enabling over-SSL/STARTTLS support.
This module inherits all the methods from Net::SMTP. You may use all the friendly
options that came bundled with Net::SMTP.
You can control the SSL usage with the options of new() constructor method.
'doSSL' option is the switch, and, If you would like to control detailed SSL settings,
you can set SSL_* options that are brought from IO::Socket::SSL. Please see the
document of IO::Socket::SSL about these options detail.
Just one method difference from the Net::SMTP, you may select SMTP AUTH mechanism
as the third option of auth() method.
=head1 METHODS
Most of all methods of Net::SMTP are inherited as is, except auth().
=over 4
=item auth ( USERNAME, PASSWORD [, AUTHMETHOD])
Attempt SASL authentication through Authen::SASL module. AUTHMETHOD is your required
method of authentication, like 'CRAM-MD5', 'LOGIN', ... etc. the default is 'CRAM-MD5'.
=back
=head1 SEE ALSO
L<Net::SMTP>,
L<IO::Socket::SSL>,
L<Authen::SASL>
=head1 AUTHOR
Tomo.M <tomo at cpan.org>
=head1 COPYRIGHT
Copyright (c) 2013 Tomo.M All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut