Solved

SMTP cannot create smtp object

Posted on 2008-10-08
11
898 Views
Last Modified: 2010-05-18
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

0
Comment
Question by:kmonarch
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 22674714
Line 3 should use the 'new' method, not net

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

Author Comment

by:kmonarch
ID: 22674896
That's a typo. Good catch, but that's not the problem.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22674975
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

0
 
LVL 28

Expert Comment

by:FishMonger
ID: 22676429
IMO, MIME::Lite is cleaner and easier.

http://search.cpan.org/~rjbs/MIME-Lite-3.021/lib/MIME/Lite.pm
0
 

Author Comment

by:kmonarch
ID: 22678786
Yes I used the actualy smtp server. No, MIME::Lite is not an option, I need to use smtp.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 39

Expert Comment

by:Adam314
ID: 22678930
Is your SMTP server up to date?  
0
 

Author Comment

by:kmonarch
ID: 22678961
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.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 22679005
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.
0
 

Author Comment

by:kmonarch
ID: 22679285
How do I check the version of my SMTP server?
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 22679373
perl -MNet::SMTP -e 'print $Net::SMTP::VERSION'
0
 

Accepted Solution

by:
kmonarch earned 0 total points
ID: 23465823
My @INC was pointing to an older perl version which didn't support SMTP. I added the correct path at the beginning of the script and it worked. Thanks for your help.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now