Reputation: 23749
I am developing an application to send emails through SMTP. I have a server, that supports both SMTP and SMTP::TLS.
Sending though SMTP works. Here is the code:
#!/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,
});
my $email = Email::Simple->create(
header => [
To => '[email protected]',
From => $smtpuser,
Subject => 'Hi!',
],
body => "This is my message\n",
);
sendmail($email, { transport => $transport });
Sending through SMTP::TLS doesn't work.
#!/usr/bin/perl
use strict;
use warnings;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP::TLS ();
use Email::Simple ();
use Email::Simple::Creator ();
my $smtpserver = 'server.com';
my $smtpport = 465;
my $smtpuser = '[email protected]';
my $smtppassword = 'secret';
my $transport = Email::Sender::Transport::SMTP::TLS->new({
host => $smtpserver,
port => $smtpport,
username => $smtpuser,
password => $smtppassword,
debug => 1,
});
my $email = Email::Simple->create(
header => [
To => '[email protected]',
From => $smtpuser,
Subject => 'Hi!',
],
body => "This is my TLS message\n",
);
sendmail($email, { transport => $transport });
How can I debug, what's going on? In Email::Sender::Transport::SMTP
I got debug messages, after adding debug => 1
. But in SMTP::TLS
I don't get it.
Currently TLS version just hangs.
Upvotes: 1
Views: 2474
Reputation: 1016
try with https://metacpan.org/pod/Email::Sender::Transport::SMTPS
in 0.03 that I just shipped. I added debug => 1.
Upvotes: 1
Reputation: 361
In the documentation, the author appears to wrap the sendmail method in a try/catch like so:
use strict;
use warnings;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP::TLS;
use Try::Tiny;
my $smtpserver = 'server.com';
my $smtpport = 2525;
my $smtpuser = '[email protected]';
my $smtppassword = 'secret';
my $transport = Email::Sender::Transport::SMTP::TLS->new({
host => $smtpserver,
port => $smtpport,
username => $smtpuser,
password => $smtppassword,
debug => 1,
});
my $email = Email::Simple->create(
header => [
To => '[email protected]',
From => $smtpuser,
Subject => 'Hi!',
],
body => "This is my TLS message\n",
);
try {
sendmail($message, { transport => $transport });
} catch {
die "Error sending email: $_";
};
Also, he admits that the module is in alpha phase and to use at your own risk.
Upvotes: 0