Showing posts with label Perl Script tricks. Show all posts
Showing posts with label Perl Script tricks. Show all posts

Thursday, February 08, 2007

Perl ERROR: Can't call method "mail" on an undefined value at smtp.pl line 10.

As confusing at it sounds, this means your smtp object has not been sucessfully constructed. I know the error message reads more like a problem with the "mail" method, but it is actually because the SMTP obj was not initialized.


Try this:
#!/usr/bin/perl -w
use Net::SMTP;
$smtp_test = Net::SMTP->new('smtp.mail.com',
Timeout => 30,
Debug => 1,)|| print "ERROR creating SMTP obj: $! \n";
print "SMTP obj created.";

If you see "ERROR createing SMTP obj" then you know the SMTP object is not created correctly.


Some times, this is because the SMTP package was not installed right, some times, it may because the SMTP protocal is blocked, sometimes it means something else is wrong.