email - Error: need MAIL command when using smtp with perl -


i trying send emails using mime::lite perl module , through smtp authentication. unfortunately doesn't work. shows

error: need mail command, error: command not implemented

here updated code snippet , debug output.

#!/usr/bin/perl use warnings; use strict; use mime::lite; use net::smtp; use mime::base64;   $smtp = net::smtp->new(<mail host>,port=>587,debug=>1)or die; $smtp->starttls(); $smtp->auth($username,$password) or die $!; $msg = mime::lite -> new (     => 'from@mail.com',      => 'to@mail.com',    subject  => 'testing text message',   data     => 'how\'s going.' );  $smtp->mail(<from mail>); $smtp->to(<to mail>); $smtp -> data(); $smtp -> datasend( $msg->as_string() ); $smtp -> dataend();  print $smtp ->message(); $smtp -> quit; 

debug output:

net::smtp>>> net::smtp(3.10) net::smtp>>>   net::cmd(3.10) net::smtp>>>     exporter(5.68) net::smtp>>>   io::socket::inet6(2.71) net::smtp>>>     io::socket(1.36) net::smtp>>>       io::handle(1.34) net::smtp=glob(0x1e0a920)<<< 220 email-smtp.amazonaws.com esmtp simpleemailservice-2108164273 5rjaqr5zfi284sdt1kwu net::smtp=glob(0x1e0a920)>>> ehlo localhost.localdomain net::smtp=glob(0x1e0a920)<<< 250-email-smtp.amazonaws.com net::smtp=glob(0x1e0a920)<<< 250-8bitmime net::smtp=glob(0x1e0a920)<<< 250-size 10485760 net::smtp=glob(0x1e0a920)<<< 250-starttls net::smtp=glob(0x1e0a920)<<< 250-auth plain login net::smtp=glob(0x1e0a920)<<< 250 ok net::smtp=glob(0x1e0a920)>>> starttls net::smtp=glob(0x1e0a920)<<< 220 ready start tls net::smtp::_ssl=glob(0x1e0a920)>>> ehlo localhost.localdomain net::smtp::_ssl=glob(0x1e0a920)<<< 250-email-smtp.amazonaws.com net::smtp::_ssl=glob(0x1e0a920)<<< 250-8bitmime net::smtp::_ssl=glob(0x1e0a920)<<< 250-size 10485760 net::smtp::_ssl=glob(0x1e0a920)<<< 250-starttls net::smtp::_ssl=glob(0x1e0a920)<<< 250-auth plain login net::smtp::_ssl=glob(0x1e0a920)<<< 250 ok died @ test_script.pl line 17. 

please let me know solution this.

thank in advance!

your code not have error checking , that's why you've missed authentication failed:

net::smtp_auth=glob(0x13085a8)>>> auth login net::smtp_auth=glob(0x13085a8)<<< 530 must issue starttls command first 

and because authentication failed not accept sending mail, i.e. $smtp->mail('admin@testadmin.com'); result in error: need mail command, error: command not implemented.

unfortunately, very old net::smtp_auth (last update 2006) not have support starttls. but, current versions of net::smtp have support both auth (so don't need net::smtp_auth) , starttls (starting net::smtp version 3.xx).

with net::smtp 3.xx code should this:

my $smtp = net::smtp->new( '<emailhost>') or die; $smtp->starttls or die; $smtp->auth('<username>', '<password>') or die; ... 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -