Click here to get back home

net smtp help

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
net smtp help rjngh2005 10-24-2006
---> Re: net smtp help harryfmudd [AT]...10-24-2006
Posted by rjngh2005 on October 24, 2006, 4:02 pm
Please log in for more thread options


This is on a Windows 2000 desktop.

I have activestate perl installed

using ppm I have downloaded the libnet module from ActiveState ppm2
repository

next I rebooted my desktop.




I have checked and have found the following files


c:\perl\lib\net\smtp.pm
c:\perl\site\lib\net\smtp.pm



I guess you have to compile this on a unix box
but I am not sure if you have to compile this on a Windows 2000
desktop.


The code is given below.


use warnings;
use Net::SMTP;
$server = 'ip_address';
$to = 'abc@test.com';
$from_email = 'abc@test.com';
$subject = 'hello, email';
$smtp = Net::SMTP->new($server);
$smtp->mail($from_email);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("Subject: $subject\n\n");
$smtp->datasend("This will be the body of the message.\n");
$smtp->datasend("\n--\nVery Official Looking .sig here\n");
$smtp->dataend();
$smtp->quit();
print "done\n";


The error message is as below

Can't call method "mail" on an undefined value at test2.pl line 8.


Please help


Posted by harryfmudd [AT] comcast [DOT] on October 24, 2006, 6:49 pm
Please log in for more thread options


rjngh2005@gmail.com wrote:
> This is on a Windows 2000 desktop.
>
> I have activestate perl installed
>
> using ppm I have downloaded the libnet module from ActiveState ppm2
> repository
>
> next I rebooted my desktop.
>
>
>
>
> I have checked and have found the following files
>
>
> c:\perl\lib\net\smtp.pm
> c:\perl\site\lib\net\smtp.pm
>
>
>
> I guess you have to compile this on a unix box
> but I am not sure if you have to compile this on a Windows 2000
> desktop.
>

I doubt the need to compile - in fact, Active State's PPM packages are
supposed to be already compiled when you get them.

What "Can't call method xyzzy on an undefined value" means is that you
didn't get a Net::SMTP object back from the "new()." In general you
should _always_ check when you instantiate an object if there is any way
the instantiation could fail. And in general when you see this message
you should assume the instantiation failed, and investigate along those
lines.

Unfortunately, the Net::SMTP docs are less than clear on how you can get
a useful error. Two good places to look are always $! and $@. So:

>
> The code is given below.
>
>
> use warnings;
> use Net::SMTP;
> $server = 'ip_address';
> $to = 'abc@test.com';
> $from_email = 'abc@test.com';
> $subject = 'hello, email';
> ### $smtp = Net::SMTP->new($server);

$smtp = Net::SMTP->new ($server) or die <<eod;
Error - Failed to create Net::SMTP object
$! = $!
$@ = $@
eod

> $smtp->mail($from_email);
> $smtp->to($to);
> $smtp->data();
> $smtp->datasend("To: $to\n");
> $smtp->datasend("Subject: $subject\n\n");
> $smtp->datasend("This will be the body of the message.\n");
> $smtp->datasend("\n--\nVery Official Looking .sig here\n");
> $smtp->dataend();
> $smtp->quit();
> print "done\n";
>

When I do this, I get

Error - Failed to create Net::SMTP object
$! = Invalid argument
$@ = Net::SMTP: Bad hostname 'ip_address'

Which in retrospect is obvious.

The trick is, what server do you give it? If it's not test.com, it will
have to have routing enabled, which will plunge you into the wonders of
configuring SMTP servers. Good luck.

Tom Wyant

Posted by rjngh2005 on October 24, 2006, 7:38 pm
Please log in for more thread options



harryfmudd [AT] comcast [DOT] net wrote:
> rjngh2005@gmail.com wrote:
> > This is on a Windows 2000 desktop.
> >
> > I have activestate perl installed
> >
> > using ppm I have downloaded the libnet module from ActiveState ppm2
> > repository
> >
> > next I rebooted my desktop.
> >
> >
> >
> >
> > I have checked and have found the following files
> >
> >
> > c:\perl\lib\net\smtp.pm
> > c:\perl\site\lib\net\smtp.pm
> >
> >
> >
> > I guess you have to compile this on a unix box
> > but I am not sure if you have to compile this on a Windows 2000
> > desktop.
> >
>
> I doubt the need to compile - in fact, Active State's PPM packages are
> supposed to be already compiled when you get them.
>
> What "Can't call method xyzzy on an undefined value" means is that you
> didn't get a Net::SMTP object back from the "new()." In general you
> should _always_ check when you instantiate an object if there is any way
> the instantiation could fail. And in general when you see this message
> you should assume the instantiation failed, and investigate along those
> lines.
>
> Unfortunately, the Net::SMTP docs are less than clear on how you can get
> a useful error. Two good places to look are always $! and $@. So:
>
> >
> > The code is given below.
> >
> >
> > use warnings;
> > use Net::SMTP;
> > $server = 'ip_address';
> > $to = 'abc@test.com';
> > $from_email = 'abc@test.com';
> > $subject = 'hello, email';
> > ### $smtp = Net::SMTP->new($server);
>
> $smtp = Net::SMTP->new ($server) or die <<eod;
> Error - Failed to create Net::SMTP object
> $! = $!
> $@ = $@
> eod
>
> > $smtp->mail($from_email);
> > $smtp->to($to);
> > $smtp->data();
> > $smtp->datasend("To: $to\n");
> > $smtp->datasend("Subject: $subject\n\n");
> > $smtp->datasend("This will be the body of the message.\n");
> > $smtp->datasend("\n--\nVery Official Looking .sig here\n");
> > $smtp->dataend();
> > $smtp->quit();
> > print "done\n";
> >
>
> When I do this, I get
>
> Error - Failed to create Net::SMTP object
> $! = Invalid argument
> $@ = Net::SMTP: Bad hostname 'ip_address'
>
> Which in retrospect is obvious.
>
> The trick is, what server do you give it? If it's not test.com, it will
> have to have routing enabled, which will plunge you into the wonders of
> configuring SMTP servers. Good luck.
>
> Tom Wyant


Your input helped a lot!!!!

I added the code (section for die...eod)
and got the message unable to create object.

I consulted my network admin and he explained that the smtp host was
configured to allow only email from certain ip addresses and of course
my desktop was not in the list.

Hence to test things out we added my desktop ip address to the list and

Bingo.....everything worked.
I am a happy enlightened person.

Thanks a lot for pointing me in the right direction !!!!!

You have made my day


Similar ThreadsPosted
SMTP::new() October 11, 2005, 2:36 am
Net::SMTP July 25, 2006, 8:44 am
Net::Telnet and SMTP June 13, 2005, 11:01 am
Question on NET::SMTP new() October 11, 2005, 2:32 am
SMTP: "to" or/and "recipient" question. November 11, 2005, 8:52 am
Net::SMTP Can't get AUTH working... November 2, 2006, 5:39 pm
Installing Net::SMTP as non-root March 19, 2007, 4:03 pm
"Host =>" in the Net::SMTP module August 15, 2007, 8:37 am
RFC: new module Net::SMTP::PostfixExt February 20, 2008, 3:49 pm
Net::SMTP - Unknown callback May 15, 2008, 6:45 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap