MIME::Lite - Cannot send mail [SMTP auth() command not supported on smtp.gmail.com]

血红的双手。 提交于 2019-12-14 01:36:06

问题


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

output

     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

Can anyone let me know whats going wrong and how to fix it ?


回答1:


MIME::Lite - sending via Gmail [SMTPS - Net::SMTP 3.05]

WARNING: MIME::Lite filters parameters passed to Net::SMTP - see MIME::Lite 3.030 - NET::SMTP with smtps (port 465)

AFAIK Gmail offers SMTP AUTH overecypted connections
(over SMTPS connections or after STARTTLS SMTP command).

With Net::SMTP 3.05 you may use SMTPS as a clean fix.
Net::SMTP versions below 3.0 do not support SMTPS.
[ WARNING: see 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




回答2:


MIME::Lite is 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 });


来源:https://stackoverflow.com/questions/28337178/mimelite-cannot-send-mail-smtp-auth-command-not-supported-on-smtp-gmail-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!