I have following code to send an email in Perl:
#!/usr/bin/perl
use MIME::Lite;
$to = \'toid@domain.com\';
$cc = \'ccid@domain.com\';
$from = \'fromid@doma
MIME::Lite is (as ThisSuitIsNotBlack notes) deprecated.
This works for me, using the preferred Email::Sender:
use strict;
use warnings;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTPS ();
use Email::Simple ();
use Email::Simple::Creator ();
my $smtpserver = 'server';
my $smtpport = 587;
my $smtpuser = 'username';
my $smtppassword = 'password';
my $transport = Email::Sender::Transport::SMTPS->new({
host => $smtpserver,
port => $smtpport,
ssl => "starttls",
sasl_username => $smtpuser,
sasl_password => $smtppassword,
});
my $email = Email::Simple->create(
header => [
To => 'mymail@gmail.com',
From => 'sender@example.com',
Subject => 'Hi!',
],
body => "This is my message\n",
);
sendmail($email, { transport => $transport });
Somebody filed a bug report for this several years ago. The maintainer's response was:
This is unlikely to be fixed.
MIME::Lite does not support Net::SMTP::TLS, and I don't see myself implementing that in the future. I strongly suggest moving off of MIME::Lite to tools like Email::Sender and Email::MIME or other more-supported tools.
Note that you shouldn't even be using MIME::Lite
in the first place, since the documentation recommends against it:
WAIT!
MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue weird bug reports, and it is not receiving a large amount of refactoring due to the availability of better alternatives. Please consider using something else.
It can be fixed with Net::SMTP 3.05 (the latest version at CPAN). It supports SMTPS and STARTTLS.
[ WARNING: see MIME::Lite 3.030 - NET::SMTP with smtps (port 465) ]
# It should work with Net::SMTP 3.05
# MIME::Lite will pass SSL=>1 to Net::SMTP constructor
$msg->send('smtp', "smtp.gmail.com", SSL=>1,
AuthUser=>"myid@domain.com", AuthPass=>"mypass" );
The above worked when
my $smtpserver = 'smtp.gmail.com.';
my $smtpport = 587;
my $smtpuser = 'YourGmailHere@gmail.com';
my $smtppassword = 'password'; ## Plug in your password here
Hope this helps others.