MIME :: Lite - 无法发送邮件[smtp.gmail.com不支持SMTP auth()命令]

时间:2015-02-05 06:01:17

标签: perl email smtp gmail send

    use MIME::Lite;
    use warnings;
    use MIME::Base64;
    use Authen::SASL;
    use MIME::Lite;
    use MIME::Base64;
    use Authen::SASL;
    use warnings;
    use Net::SMTP::TLS;
    use Data::Dumper;
    use MIME::Lite;
    $to = 'pratapchintha@gmail.com';
    $cc = 'pratapchintha@gmail.com';
    $from = 'pratapchintha@gmail.com';
    $subject = 'Test Email';
$message = 'email';

$msg = MIME::Lite->new(
             From     => $from,
             To       => $to,
             Cc       => $cc,
             Subject  => $subject,
             Type     => 'multipart/mixed'
             );

 $msg->attach(Type         => 'text',
         Data         => $message
        );

$msg->attach(Type        => 'image/gif',
         Path        => 'C:\Users\chintpra\Desktop\excel\Feb_4.xls',
         Filename    => 'logo.gif',
         Disposition => 'attachment'
        );              
$msg->send('smtp', "smtp.gmail.com", AuthUser=>"$from",          AuthPass=>"*******",Debug=>1);
   print "Email Sent Successfully\n";

输出

     MIME::Lite::SMTP>>> MIME::Lite::SMTP
     MIME::Lite::SMTP>>>   Net::SMTP(3.05)
     MIME::Lite::SMTP>>>     Net::Cmd(3.05)
     MIME::Lite::SMTP>>>       Exporter(5.67)
     MIME::Lite::SMTP>>>     IO::Socket::INET(1.33)
     MIME::Lite::SMTP>>>       IO::Socket(1.34)
     MIME::Lite::SMTP>>>         IO::Handle(1.33)
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 220 mx.google.com ESMTP  gj9sm3721288pbc.32 - gsmtp
     MIME::Lite::SMTP=GLOB(0x2c030e0)>>> EHLO localhost.localdomain
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 250-mx.google.com at your service,  [123.63.237.69]
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 250-SIZE 35882577
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 250-8BITMIME`enter code here`
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 250-STARTTLS
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 250-ENHANCEDSTATUSCODES
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 250-PIPELINING
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 250-CHUNKING
     MIME::Lite::SMTP=GLOB(0x2c030e0)<<< 250 SMTPUTF8
     SMTP auth() command not supported on smtp.gmail.com

任何人都可以让我知道什么是错误的以及如何解决它?

2 个答案:

答案 0 :(得分:1)

MIME :: Lite - 通过Gmail [SMTPS - Net :: SMTP 3.05]

发送

警告MIME::Lite过滤传递给Net::SMTP的参数 - 请参阅MIME::Lite 3.030 - NET::SMTP with smtps (port 465)

AFAIK Gmail提供SMTP AUTH过度加密连接
(通过SMTPS连接或STARTTLS SMTP命令后)。

使用Net :: SMTP 3.05,您可以使用SMTPS作为干净修复 低于3.0的Net :: SMTP版本不支持SMTPS [警告:请参阅MIME::Lite 3.030 - NET::SMTP with smtps (port 465)]

$msg->send('smtp', "smtp.gmail.com", 
  SSL=>1,
  AuthUser=>"$from",  AuthPass=>"*******",
  Debug=>1);

Net::SMTP 3.05 documentation

答案 1 :(得分:1)

不推荐使用MIME :: Lite。

这适用于我,使用首选的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 });