net smtp help

net smtp help

am 24.10.2006 22:02:33 von rjngh2005

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

Re: net smtp help

am 25.10.2006 00:49:22 von unknown

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 < 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

Re: net smtp help

am 25.10.2006 01:38:50 von rjngh2005

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 < > 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