Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

perl - Why do I get "SMTP Failed to connect to mail server:" when I try to send an email to a Gmail account using MIME::Lite?

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
";

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...