LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   run perl module error (https://www.linuxquestions.org/questions/linux-newbie-8/run-perl-module-error-4175503197/)

byran cheung 04-28-2014 04:19 AM

run perl module error
 
I want to create a perl function for sending mail, I have successfully installed the perl module Net::SMTP .

When I run the below script but got the below errors , would advise what is wrong in my case ? thanks

Code:

my script
============

#!/usr/bin/perl
use warnings;
use strict;
use Net::SMTP;

my $smtpserver = 'localhost';
my $smtpport = 25;
my $smtpuser  = 'user';
my $smtppassword = 'password';

my $smtp = Net::SMTP->new($smtpserver, Port=>$smtpport, Timeout => 10, Debug => 1);
die "Could not connect to server!\n" unless $smtp;

$smtp->auth($smtpuser, $smtppassword);
$smtp->to('jpdees@gmail.com');
$smtp->data();
$smtp->datasend("To: mymail\@gmail.com\n");
$smtp->quit;

Code:

run script error
================

Net::SMTP>>> Net::SMTP(2.33)
Net::SMTP>>>  Net::Cmd(2.30)
Net::SMTP>>>    Exporter(5.58)
Net::SMTP>>>  IO::Socket::INET(1.29)
Net::SMTP>>>    IO::Socket(1.29)
Net::SMTP>>>      IO::Handle(1.25)
Net::SMTP=GLOB(0x10398490)<<< 220 localhost.localdomain ESMTP Sendmail ; Mon, 28 Apr 2014 17:16:22 +0800
Net::SMTP=GLOB(0x10398490)>>> EHLO localhost.localdomain
Net::SMTP=GLOB(0x10398490)<<< 250-localhost.localdomain Hello localhost.localdomain [127.0.0.1], pleased to meet you
Net::SMTP=GLOB(0x10398490)<<< 250-ENHANCEDSTATUSCODES
Net::SMTP=GLOB(0x10398490)<<< 250-PIPELINING
Net::SMTP=GLOB(0x10398490)<<< 250-8BITMIME
Net::SMTP=GLOB(0x10398490)<<< 250-SIZE 20000000
Net::SMTP=GLOB(0x10398490)<<< 250-DSN
Net::SMTP=GLOB(0x10398490)<<< 250-ETRN
Net::SMTP=GLOB(0x10398490)<<< 250-DELIVERBY
Net::SMTP=GLOB(0x10398490)<<< 250 HELP
Net::SMTP=GLOB(0x10398490)>>> RCPT TO:<jpdees@gmail.com>
Net::SMTP=GLOB(0x10398490)<<< 503 5.0.0 Need MAIL before RCPT
Net::SMTP=GLOB(0x10398490)>>> DATA
Net::SMTP=GLOB(0x10398490)<<< 503 5.0.0 Need MAIL command
Net::SMTP=GLOB(0x10398490)>>> To: mymail@gmail.com
Net::SMTP=GLOB(0x10398490)>>> .
Net::SMTP=GLOB(0x10398490)<<< 500 5.5.1 Command unrecognized: "To: mymail@gmail.com"
Net::SMTP=GLOB(0x10398490)>>> QUIT
Net::SMTP=GLOB(0x10398490)<<< 500 5.5.1 Command unrecognized: "."

Code:

maillog error
==============
s3S9GMHo009143: localhost.localdomain [127.0.0.1] did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA


linosaurusroot 04-28-2014 05:24 AM

Your error
Quote:

did not issue MAIL/EXPN/VRFY/ETRN during connection to MTA
is a clue ... looks like you are missing
Code:

smtp->mail("sender\@example.com");

byran cheung 04-28-2014 11:14 AM

thanks reply ,

I changed to as below , but still get the error , would advise what is wrong ?

Code:

my script
=========
my $smtpserver = 'localhost';
my $smtpport = 25;
my $smtpuser  = 'user';
my $smtppassword = 'password';

my $smtp = Net::SMTP->new($smtpserver, Port=>$smtpport, Timeout => 10, Debug => 1);
die "Could not connect to server!\n" unless $smtp;

$smtp->auth($smtpuser, $smtppassword);
$smtp->to('jpdees@gmail.com');
$smtp->data();
$smtp->datasend("To: jpdees\@gmail.com\n");
$smtp->mail("sender\@example.com");
$smtp->quit;

Code:

run error
==========
Net::SMTP=GLOB(0x198944e0)<<< 250-PIPELINING
Net::SMTP=GLOB(0x198944e0)<<< 250-8BITMIME
Net::SMTP=GLOB(0x198944e0)<<< 250-SIZE 20000000
Net::SMTP=GLOB(0x198944e0)<<< 250-DSN
Net::SMTP=GLOB(0x198944e0)<<< 250-ETRN
Net::SMTP=GLOB(0x198944e0)<<< 250-DELIVERBY
Net::SMTP=GLOB(0x198944e0)<<< 250 HELP
Net::SMTP=GLOB(0x198944e0)>>> RCPT TO:<jpdees@gmail.com>
Net::SMTP=GLOB(0x198944e0)<<< 503 5.0.0 Need MAIL before RCPT
Net::SMTP=GLOB(0x198944e0)>>> DATA
Net::SMTP=GLOB(0x198944e0)<<< 503 5.0.0 Need MAIL command
Net::SMTP=GLOB(0x198944e0)>>> To: jpdees@gmail.com
Net::SMTP=GLOB(0x198944e0)>>> .
Net::SMTP=GLOB(0x198944e0)<<< 500 5.5.1 Command unrecognized: "To: jpdees@gmail.com"
Net::SMTP=GLOB(0x198944e0)>>> MAIL FROM:<sender@example.com>
Net::SMTP=GLOB(0x198944e0)<<< 500 5.5.1 Command unrecognized: "."
Net::SMTP=GLOB(0x198944e0)>>> QUIT
Net::SMTP=GLOB(0x198944e0)<<< 250 2.1.0 <sender@example.com>... Sender ok

Code:

/var/log/maillog
=================
sendmail[9355]: s3SG4svF009355: from=<sender@example.com>, size=0, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]


linosaurusroot 04-28-2014 11:21 AM

error message says
Quote:

Need MAIL before RCPT
need
Code:

$smtp->mail("sender\@example.com");
before
Code:

->to

byran cheung 04-28-2014 11:50 AM

thanks reply ,

I still not get the mail , but from the maillog shown that the mail has been successfully sent , I will check my smtp first .

another question , what is the below smtpuser stands for , do I need to input any user id to it ?

my $smtpuser = 'user';
my $smtppassword = 'password';


thanks

linosaurusroot 04-28-2014 12:04 PM

These appear in the code as
Code:

$smtp->auth($smtpuser, $smtppassword);
so if you aren't using real values there I'd drop that line.

byran cheung 04-28-2014 12:10 PM

Quote:

Originally Posted by linosaurusroot (Post 5160625)
These appear in the code as
Code:

$smtp->auth($smtpuser, $smtppassword);
so if you aren't using real values there I'd drop that line.

what is the real values , is it linux login ID or smtp ID ? thanks

byran cheung 04-28-2014 12:19 PM

I just check the maillog and found that the mail is relay to another smtp server , not relay to localhost ( relay=[127.0.0.1] ) , I found that the mail sent from this server was use localhost relay , but this perl script relay another smtp server , would advise what is the problem ? thanks

byran cheung 04-29-2014 02:39 AM

hi ,

My final version of script is below , but I can't get the mail , when use sendmail to send , it is OK .

I checked the maillog , everything seems normal ( I tried to use sendmail to send mail , the log is similiar ) .

Would advise what will be the possible of the error ? thanks

#!/usr/bin/perl
use warnings;
use strict;
use Net::SMTP;

my $smtpserver = 'localhost';
my $smtpport = 25;
my $smtpuser = 'username';
my $smtppassword = 'password';

my $smtp = Net::SMTP->new($smtpserver, Port=>$smtpport, Timeout => 10, Debug => 1);
die "Could not connect to server!\n" unless $smtp;

#$smtp->auth($smtpuser, $smtppassword);
$smtp->mail("amy\@localhost.localdomain");
$smtp->to('dusse@gmail.com');
$smtp->data();
$smtp->datasend("To: dusse\@gmail.com\n");
$smtp->quit;


All times are GMT -5. The time now is 11:40 AM.