title: Debugging Email::Sender::Simple with Email::Sender::Transport::SMTPS
body: <p>I'm writing an email service which sends data to my users with <code>Email::Sender::Simple</code> and <code>Email::Sender::Transport::SMTPS</code>. Right now, I've got a package which should just take some inputs and send an e-mail:</p>
  
  <pre><code>package MyApp::Service::Mail;
  
  use Email::Sender::Simple qw(sendmail);
  use Email::Simple;
  use Email::Sender::Transport::SMTPS;
  use Try::Tiny;
  use Dancer;
  
  use constant CANT_SEND_MAIL    =&gt; -1;
  use constant SENT_SUCCESSFULLY =&gt; 1;
  
  sub new {
      my $class   = shift;
      my $self    = {};
  
      bless  $self, $class;
      return $self;
  }
  
  sub sendEmail {
      my $self    = shift;
      my $to      = shift;
      my $subject = shift;
      my $body    = shift;
      my $failed  = 0;
  
      my $email = Email::Simple-&gt;create(
          header =&gt; [
              To      =&gt; $to,
              From    =&gt; 'noreply@myapp.com',
              Subject =&gt; $subject
          ],
          body =&gt; $body
      );
  
      my $transport = Email::Sender::Transport::SMTPS-&gt;new({
          host          =&gt; config-&gt;{smtp_host},
          port          =&gt; config-&gt;{smtp_port},
          sasl_username =&gt; config-&gt;{smtp_username},
          sasl_password =&gt; config-&gt;{smtp_password},
          ssl           =&gt; 'ssl'
      });
  
      try {
          sendmail($email, {transport =&gt; $transport});
      } catch {
          $failed = 1;
      }
  
      return $self-&gt;CANT_SEND_MAIL if ($failed eq 1);
      return $self-&gt;SENT_SUCCESSFULLY;
  }
  
  1;
  </code></pre>
  
  <p>This is based heavily on the <a href="https://metacpan.org/pod/Email%3a%3aSender%3a%3aTransport%3a%3aSMTPS" rel="nofollow">example from the CPAN page for the modules involved</a>.</p>
  
  <p>Note that those config variables are coming from <code>Dancer</code>s config.yml, and I have confirmed they are being passed in correctly. I have also confirmed that <code>$to</code>, <code>$body</code> and <code>$subject</code> contain what I expect them to.</p>
  
  <p>The <code>sendEmail</code> function is being called and returning 1 (<code>SENT_SUCCESSFULLY</code>) but I cannot see anything in the Sent box on my e-mail client, and there is nothing at the receiving address either. I've been trying to find some kind of debug function to delve deeper into why this is failing, but to no avail.</p>
  
  <p>Code calling this is:</p>
  
  <pre><code>package MyApp::Service::Mail::User;
  
  use MyApp::Service::Mail;
  our @ISA = qw(MyApp::Service::Mail);
  
  sub sendPasswordByEmail {
      my $self     = shift;
      my $to       = shift;
      my $username = shift;
  
      my $subject = "Test E-Mail";
  
      (my $body = &lt;&lt; "    END_MESSAGE") =~ s/^ {4}//gm;
      Dear $username,
  
      This is a test e-mail.
      END_MESSAGE
  
      return $self-&gt;sendEmail($to, $subject, $body);
  }
  
  1;
  </code></pre>
  
  <p>I can confirm the SMTP account definitely works as I use it in my e-mail client (Thunderbird). Any suggestions as to why this function could be returning 1 with no success? Is there a way to debug the connection between this and my SMTP server (it's 3rd party so can't check the logs) to see if a connection is being established and what's being passed / whether there's a problem?</p>