如何调试Email :: Sender :: Transport :: SMTP :: TLS?

时间:2014-08-06 12:22:46

标签: perl email smtp

我正在开发一个通过SMTP发送电子邮件的应用程序。我有一台服务器,支持SMTP和SMTP :: TLS。

通过SMTP发送工作。这是代码:

#!/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     = 'test@server.com';
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      => 'my-email@gmail.com',
    From    => $smtpuser,
    Subject => 'Hi!',
  ],
  body => "This is my message\n",
);

sendmail($email, { transport => $transport });

通过SMTP :: TLS发送不起作用。

#!/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     = 'test@server.com';
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      => 'my-email@gmail.com',
    From    => $smtpuser,
    Subject => 'Hi!',
  ],
  body => "This is my TLS message\n",
);

sendmail($email, { transport => $transport });

我如何调试,发生了什么?在Email::Sender::Transport::SMTP中,我在添加debug => 1后收到了调试消息。但是在SMTP::TLS我没有得到它。

目前TLS版本暂停。

2 个答案:

答案 0 :(得分:1)

尝试使用https://metacpan.org/pod/Email::Sender::Transport::SMTPS

我刚刚发货的0.03。我添加了debug => 1。

答案 1 :(得分:0)

documentation中,作者似乎将sendmail方法包装在try / catch中,如下所示:

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     = 'test@server.com';
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      => 'my-email@gmail.com',
    From    => $smtpuser,
    Subject => 'Hi!',
  ],
  body => "This is my TLS message\n",
);

try {
        sendmail($message, { transport => $transport });
    } catch {
        die "Error sending email: $_";
    };

此外,他承认该模块处于alpha阶段,使用风险自负。