Search code examples
perlemailsmtpgmailsend

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


    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 = '[email protected]';
    $cc = '[email protected]';
    $from = '[email protected]';
    $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 ?


Solution

  • 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