in reply to Net::SMTP error

So if should try something like?
if (!$smtp=Net::SMTP->new($out_server)) {try again later;}


-kevin

Replies are listed 'Best First'.
Re: Re: Net::SMTP error
by Gerard (Pilgrim) on Dec 11, 2003 at 21:40 UTC
    Sounds good to me. Personally I do
    my $smtp = Net::SMTP->new($smtpServer, Timeout => 60) || &do_some_stuf +f $!;

    But whatever works for you
    Regards,
    Gerard
      Ummm, perhaps you meant to use 'or' instead of '||' here. '||' has higher precedence than '=', where 'or' has lower precedence than '=', so it is not doing what you think it's doing when you interchange between the two.

      In you code you had -
      my $smtp = Net::SMTP->new($smtpServer, Timeout => 60) || &do_some_stuf +f $!;
      where I assume that &do_some_stuff does some error handling. May be you are not aware, it is actually doing this instead -
      my $smtp = (Net::SMTP->new(....) || &do_some_stuff...);
      if the object creation fails, your $smtp ends up with whatever is returned from 'do_some_stuff'.

      So the more correct way to do error handling here should be -
      my $smtp = Net::SMTP->new(....) or &do_some_stuff $!;
      where $smtp is assigned to the new object first, and if it is undefined because of failed connection, then the 'do_some_stuff' error handling will kick in.

        Hey guys, with some testing I found, what imho might be a better way. You can't use if (!$smtp=Net::SMTP...) in the begining , it won;t accept it, but what does work is just letting the first one go, it won't crash the script if it fails. Then on the next line, test if $smtp is defined. if (!defined($smtp)) if it is defined then opening the server worked, if it is undefined, it failed and you can deal with it from there!!! thanx for your help all!

        -Kevin
      Thanx for your help!!

      -Kevin