CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
unable to get the function mail in Net:smtp

 



gauri_agr
Novice

Apr 9, 2009, 7:49 PM

Post #1 of 16 (3277 views)
unable to get the function mail in Net:smtp Can't Post

Hi All,



I have install Active perl. I have Net::SMTP module in lib. My perl is in C:/perl. I write a program send.pl a below

#!c:/Perl/bin/perl.exe

use Net::SMTP;
#Create a new object with 'new'.
$smtp = Net::SMTP->new("smtp.go4expert.com");
#Send the MAIL command to the server.
$smtp->mail("pradeep\@go4expert.com");
#Send the server the 'Mail To' address.
$smtp->to("shabbir\@go4expert.com");
#Start the message.
$smtp->data();
#Send the message.
$smtp->datasend("Hello World!\n\n");
#End the message.
$smtp->dataend();
#Close the connection to your server.
$smtp->quit();


I am getting this error

Can't call method "mail" on an undefined value at send.pl line 7.

Could any one help me where is the problem. I have checked the function in smtp.PM


Tumata
User


Apr 9, 2009, 10:33 PM

Post #2 of 16 (3274 views)
Re: [gauri_agr] unable to get the function mail in Net:smtp [In reply to] Can't Post

Hi.

Could you add following:

use warning;
use strict;

And post here output of your script. By the way, add "my" before first usage of $smtp.


KevinR
Veteran


Apr 9, 2009, 10:55 PM

Post #3 of 16 (3275 views)
Re: [gauri_agr] unable to get the function mail in Net:smtp [In reply to] Can't Post


Quote
Could any one help me where is the problem. I have checked the function in smtp.PM


The object $smtp is not getting defined. Read the Net::SMTP documentation and turn on debugging.
-------------------------------------------------


gauri_agr
Novice

Apr 10, 2009, 11:12 AM

Post #4 of 16 (3259 views)
Re: [Tumata] unable to get the function mail in Net:smtp [In reply to] Can't Post

Hi,

Thanks for the quick response. I really apreciate it.

1. when included use warning;

$ perl send.pl
Can't locate warning.pm in @INC (@INC contains: c:/Perl/site/lib c:/Perl/lib .)
at send.pl line 2.
BEGIN failed--compilation aborted at send.pl line 2.

unable to get warning.pm in google

2. When included use strict, i got the error

$ perl send.pl
Global symbol "$smtp" requires explicit package name at send.pl line 8.
Global symbol "$smtp" requires explicit package name at send.pl line 10
Global symbol "$smtp" requires explicit package name at send.pl line 12
Global symbol "$smtp" requires explicit package name at send.pl line 14
Global symbol "$smtp" requires explicit package name at send.pl line 16
Global symbol "$smtp" requires explicit package name at send.pl line 18
Global symbol "$smtp" requires explicit package name at send.pl line 20
Execution of send.pl aborted due to compilation errors.

3. so as suggested I used my before $smtp , i got the error

$ perl send.pl
Can't call method "mail" on an undefined value at send.pl line 10.


I am new to perl programming....


KevinR
Veteran


Apr 10, 2009, 1:52 PM

Post #5 of 16 (3254 views)
Re: [gauri_agr] unable to get the function mail in Net:smtp [In reply to] Can't Post


Quote
1. when included use warning;


that should have been:


Code
use warnings;


Note the "s" on the end of "warnings".
-------------------------------------------------


gauri_agr
Novice

Apr 10, 2009, 6:42 PM

Post #6 of 16 (3253 views)
Re: [KevinR] unable to get the function mail in Net:smtp [In reply to] Can't Post

Thanks for your help. Yes its "warnings" But still getting error

Can't call method "mail" on an undefined value at send.pl line 10.


KevinR
Veteran


Apr 10, 2009, 8:19 PM

Post #7 of 16 (3249 views)
Re: [gauri_agr] unable to get the function mail in Net:smtp [In reply to] Can't Post

I suggested that you read the modules documentation and enable debugging, have you done that?
-------------------------------------------------


gauri_agr
Novice

Apr 11, 2009, 3:00 PM

Post #8 of 16 (3245 views)
Re: [KevinR] unable to get the function mail in Net:smtp [In reply to] Can't Post

hi,

I debug as below

$ perl -d send.pl

Loading DB routines from perl5db.pl version 1.3
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(send.pl:7): my $smtp = Net::SMTP->new('mail.yahoo.com');

DB<1> n
main::(send.pl:9): $smtp->mail("pradeep\@go4expert.com");

DB<1> s
Can't call method "mail" on an undefined value at send.pl line 9.
at send.pl line 9
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.


please let me know how should i go further?



Thanks

Gauri


KevinR
Veteran


Apr 11, 2009, 4:20 PM

Post #9 of 16 (3239 views)
Re: [gauri_agr] unable to get the function mail in Net:smtp [In reply to] Can't Post

Read the modules documentation and turn on the modules debugging, not perls debugging. Thats the last time I want to repeat that.
-------------------------------------------------


FishMonger
Veteran / Moderator

Apr 11, 2009, 4:44 PM

Post #10 of 16 (3236 views)
Re: [KevinR] unable to get the function mail in Net:smtp [In reply to] Can't Post

See
http://codingforums.com/showthread.php?t=163675


KevinR
Veteran


Apr 12, 2009, 10:27 AM

Post #11 of 16 (3216 views)
Re: [FishMonger] unable to get the function mail in Net:smtp [In reply to] Can't Post


In Reply To


Thanks for the heads up Fish Wink
-------------------------------------------------


gauri_agr
Novice

Apr 12, 2009, 12:13 PM

Post #12 of 16 (3213 views)
Re: [KevinR] unable to get the function mail in Net:smtp [In reply to] Can't Post

I have enabled the module debugging also added these lines as suggested and getting the following error

$ perl -d send.pl -W

Loading DB routines from perl5db.pl version 1.3
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main:send.pl:8): my $server='mail.yahoo.com';

DB<1> n
main:send.pl:9): my $smtp = Net::SMTP->new($server, Debug => 1) or die("F
ailed to connect to $server: $!");

DB<1> n
Failed to connect to mail.yahoo.com: Unknown error at send.pl line 9.
at send.pl line 9Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.


gauri_agr
Novice

Apr 12, 2009, 12:13 PM

Post #13 of 16 (3212 views)
Re: [gauri_agr] unable to get the function mail in Net:smtp [In reply to] Can't Post

 

Join Date: Apr 2009 Posts: 3 Thanks: 0 Thanked 0 Times in 0 Posts DO i need to start any service in windows xp that will allow my program to work as it is failing at the connection with mail.yahoo.com

I also tried sendmail on the commandline that also was giving me socket error...i guess i have some basic service missing...


Tumata
User


Apr 15, 2009, 5:50 AM

Post #14 of 16 (3187 views)
Re: [gauri_agr] unable to get the function mail in Net:smtp [In reply to] Can't Post

While you debugging your code try print $smtp variable value.


gauri_agr
Novice

Apr 15, 2009, 7:26 AM

Post #15 of 16 (3184 views)
Re: [Tumata] unable to get the function mail in Net:smtp [In reply to] Can't Post

its not diplaying any thing. Actually I am unable to telnet to any mail server. when i called comcast they said they can only help me to configure the outlook to send email from different port other than 25..that i already figureout.

My question is "is it psosible to send email from command line if port 25 is blocked by the ISP in windows xp"? If so what is the work around?


Tumata
User


Apr 16, 2009, 1:42 AM

Post #16 of 16 (3172 views)
Re: [gauri_agr] unable to get the function mail in Net:smtp [In reply to] Can't Post

It is looks like you make a mistake. See:

Quote
to send email from different port other than 25..

If you mean that 25 is source port then you are incorrect. It is a destination port (from your point of view). Most of the time you don't know your souce port as it is random number selected by your OS (on Linux it is >1024 for unprivileged users). So if your ISP blocked this destination port you can not connect to any SMTP server unless you create something like tunnel... But this is another story...

By the way, for future, try using sniffers. It will help you to investigate what is going wrong.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives