title: How to use perl for SMTP connection with user and SSL Auth and send emails with attachment
body: <p>I am using a SMTP mail server which require user + ssl authentication for connection. I am looking for the perl modules to connect to the mail server and send emails but doesn't found anything helpful. </p>
  
  <p>Any suggestion for perl module or any perl code would be really appreciated.</p>
  
  <h2>EDIT</h2>
  
  <p>I have tried to use Mail::Sendmail and Net::SMTP::SSL to connect to the sendmail server and send mail. Below is the sample code but getting the error user unknown.</p>
  
  <p>Error:</p>
  
  <pre><code>mail: Net::SMTP::SSL=GLOB(0x9599850) not found 
  RCPT TO: error (550 5.1.1 &lt;user@mail.com&gt;... User unknown).
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  use Mail::Sendmail;
  use Net::SMTP::SSL;
  
  my %mail = (
  From=&gt; 'user1@server.com',
  To=&gt; 'user2@server.com',
  # Cc will appear in the header. (Bcc will not)
  Subject =&gt; 'Test message',
  'X-Mailer' =&gt; "Mail::Sendmail version $Mail::Sendmail::VERSION",
  );
  
  $mail{Smtp} = Net::SMTP::SSL-&gt;new("mail.server.com", Port=&gt; 465, Debug=&gt;1);
  $mail{auth} = {user=&gt;'username', password=&gt;"password", required=&gt;1 };
  $mail{'X-custom'} = 'My custom additionnal header';
  $mail{Message} = "The message key looks terrible, but works.";
  # cheat on the date:
  $mail{Date} = Mail::Sendmail::time_to_date( time() - 86400 );
  if (sendmail %mail) { print "Mail sent OK.\n" }
  else { print "Error sending mail: $Mail::Sendmail::error \n" }
  
  print "\n\$Mail::Sendmail::log says:\n", $Mail::Sendmail::log;
  </code></pre>