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@domain.com';
$subject = 'Test Email';
$message = 'This is test email sent by Perl Script';
$msg = MIME::Lite->new(
From => $from,
To => $to,
Cc => $cc,
Subject => $subject,
Data => $message
);
$msg->send;
#$msg->send('smtp', "smtp.gmail.com", AuthUser=>"myid@domain.com", AuthPass=>"mypass" );
#$msg->send('smtp', "smtp.gmail.com", Debug=>0 );
#$msg->send('type',@args);
print "Email Sent Successfully\n";
When I run it I get the following error:
SMTP Failed to connect to mail server:
When I call $msg->send
with arguments (see the commented lines above) I get the following error:
SMTP auth() command not supported on smtp.gmail.com
How can I fix this?
MIME::Lite is (as ThisSuitIsNotBlack notes) deprecated.
This works for me, using the preferred Email::Sender:
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) ]
Somebody filed a bug report for this several years ago. The maintainer's response was:
Note that you shouldn't even be using
MIME::Lite
in the first place, since the documentation recommends against it: