Web Analytics Made Easy -
StatCounter unable to use Net:SMTP module - CodingForum

Announcement

Collapse
No announcement yet.

unable to use Net:SMTP module

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • unable to use Net:SMTP module

    hi All,

    I am tring to write a perl program to send mail. My code is

    #!c:/Perl/bin/perl.exe -w
    use warnings;
    use strict;

    use Net::SMTP;
    #Create a new object with 'new'.
    my $smtp = Net::SMTP->new('mail.yahoo.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();

    When running this program i m getting the following error

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

    DB<1>

    Please let me know where i m wrong.. I am new to windows and perl

  • #2
    Check your return values!

    my $server='mail.yahoo.com';
    my $smtp = Net::SMTP->new($server) or die("Failed to connect to $server: $!");

    Comment


    • #3
      In addition to checking the return value as Shannon recommends, you should enable debug as Kevin suggested yesterday in your cross post http://perlguru.com/gforum.cgi?post=37078#37078

      Code:
      my $server='mail.yahoo.com';
      my $smtp = Net::SMTP->new($server, [b]Debug => 1[/b]) or die("Failed to connect to $server: $!");

      Comment


      • #4
        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 9[/b][/b]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.

        Comment


        • #5
          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...

          Comment


          • #6
            Your ISP is probably blocking all third-party SMTP traffic. Try connecting to port 25 of the mail server with telnet -- if that fails, call your ISP.
            Last edited by Shannon Blonk; Apr 12, 2009, 07:30 PM. Reason: grammar

            Comment


            • #7
              Originally posted by gauri_agr View Post
              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...
              any firewall blocking maybe? Can perl connect to the internet to do other things?

              Comment


              • #8
                If your isp is Yahoo, you need to add the email account to their list before you can send email out. Sign into your yahoo email account. Click on options, email addressess. Add the email to the list. You will need to verify after that.

                Comment


                • #9
                  I can not telnet on port 25

                  $ telnet mail.yahoo.com 25
                  Connecting To mail.yahoo.com...Could not open connection to the host, on port 25
                  : Connect failed

                  MY ISP is comcast. Is it possible with comcast to enable SMTP from third party?

                  Comment


                  • #10
                    I cheked that firewall is not working also i strted the telnet services which was not working earlier. still telnet not working ..

                    Comment


                    • #11
                      I don't know what the problem could be

                      Comment


                      • #12
                        When i tried the following it works....
                        telnet smtp.comcast.net 587

                        but no other host i am able to connect

                        Comment


                        • #13
                          i tried follwoing

                          telent mail.yahoo.com 80

                          it gives me a blank scrolled screen but no connection failure. I guess that means my port 25 is blocked but i can do telnet on port 80...can any one suggest

                          Comment


                          • #14
                            ask comcast tech support

                            Comment

                            Working...
                            X