Link to home
Start Free TrialLog in
Avatar of kmonarch
kmonarch

asked on

SMTP cannot create smtp object

I am able to open a telnet session and send the email via smtp manually. I am unable to send an email via smtp with a perl script. When I try and use Net::SMTP with perl, the script fails to create the SMTP object.

When running this code, here is the response:
Net::SMTP>>> Net::SMTP(2.29)
Net::SMTP>>>   Net::Cmd(2.26)
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: Unexpected EOF on command channel at email.pl line 3
Can't call method "mail" on an undefined value at email.pl line 4

The mailhost can be connected to outside of the perl script, so what else could be the problem?
#!/usr/bin/perl
use Net::SMTP;
$smtp=Net::SMTP->net('mailhost',Debug=>1);
$smtp->mail('sender\@domain.com');
$smtp->to('recip\@domain.com');
$smtp->data();
 
$smtp->datasend("Subject: test","\n");
$smtp->datasend("testing\n");
$smtp->datasend(".\n");
 
$smtp->dataend();
$smtp->quit();

Open in new window

Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

Line 3 should use the 'new' method, not net

$smtp=Net::SMTP->new('mailhost',Debug=>1);
Avatar of kmonarch
kmonarch

ASKER

That's a typo. Good catch, but that's not the problem.
Did you replace 'mailhost' with your actual smtp server?
$smtp=Net::SMTP->new('mailhost',Debug=>1)
  or die "Could not create Net::SMTP object";

Open in new window

Avatar of FishMonger
IMO, MIME::Lite is cleaner and easier.

http://search.cpan.org/~rjbs/MIME-Lite-3.021/lib/MIME/Lite.pm
Yes I used the actualy smtp server. No, MIME::Lite is not an option, I need to use smtp.
Is your SMTP server up to date?  
Up to date in what respect? As I said in the initial posting, I am able to telnet to the smtp server and send emails. It does not appear to be a problem with the smtp server itself, just with the perl script creating an smtp object.
Up to date meaning any known bugs with the server are fixed.

There is a newer version of Net::SMTP available - 2.31.  You could try upgrading to the latest, and see if that helps.
How do I check the version of my SMTP server?
perl -MNet::SMTP -e 'print $Net::SMTP::VERSION'
ASKER CERTIFIED SOLUTION
Avatar of kmonarch
kmonarch

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial