Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Error message not showing up from Net::SMTP

by sg (Pilgrim)
on Sep 05, 2007 at 14:36 UTC ( [id://637170]=perlquestion: print w/replies, xml ) Need Help??

sg has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

Net::SMTP's sub auth() begins as:

sub auth { my (\$self, \$username, \$password) = \@_; eval { require MIME::Base64; require Authen::SASL; } or \$self->set_status(500, ["Need MIME::Base64 and Authen::SASL +todo auth"]), return 0;
In line 117, change Authen::SASL to Authen::SASLX, a non-existant module. One would think that the error message of line 118 would be given to the user. However, the failure is silent! Why?

Code to test is attached below -- need to provide a valid $smtp_host. Output from test is attached also.

Thanks

#!/use/bin/perl BEGIN {(*STDERR = *STDOUT) || die;} use diagnostics; use warnings; use strict; $| = 1; use Net::POP3; use Net::SMTP; my $smtp_host = 'smtp.host.com'; my $src_domain = 'the.org'; my $user_id = 'the_user_id'; my $password = 'the_password'; my %smtp_options = ( Host => $smtp_host, Hello => $src_domain, Debug => 4, ); if(!($mail = Net::SMTP->new(%smtp_options))) { print "ERROR: Could not open $smtp_host\n$!\n"; return -1; } if(!$mail->auth($user_id, $password)) { print "ERROR: Could not authenticate user $user_id\n$!\n"; $mail->quit(); return -1; } __END__ Net::SMTP>>> Net::SMTP(2.31) Net::SMTP>>> Net::Cmd(2.29) Net::SMTP>>> Exporter(5.60) Net::SMTP>>> IO::Socket::INET(1.31) Net::SMTP>>> IO::Socket(1.30) Net::SMTP>>> IO::Handle(1.27) Net::SMTP=GLOB(0x1b0b964)<<< 220 <smtp.host.com> ESMTP Net::SMTP=GLOB(0x1b0b964)>>> EHLO <the.org> Net::SMTP=GLOB(0x1b0b964)<<< 250-<smtp.host.com> Net::SMTP=GLOB(0x1b0b964)<<< 250-AUTH LOGIN PLAIN XYMCOOKIE Net::SMTP=GLOB(0x1b0b964)<<< 250-PIPELINING Net::SMTP=GLOB(0x1b0b964)<<< 250 8BITMIME ERROR: Could not authenticate user <user> No such file or directory Net::SMTP=GLOB(0x1b0b964)>>> QUIT Net::SMTP=GLOB(0x1b0b964)<<< 221 <smtp.host.com>

Replies are listed 'Best First'.
Re: Error message not showing up from Net::SMTP
by ikegami (Patriarch) on Sep 05, 2007 at 15:58 UTC

    What do you mean by "the failure is silent"? Your output clearly shows auth communicated the failure.

    Do you mean the error isn't in $!? $!'s content are meaningless unless a system call returned an error. You didn't make any system calls, much less one that returned an error. Perhaps you want $mail->code and/or $mail->message? (Remember, Net::SMTP objects are descendant of Net::Cmd.)

      The message in the output came from user code when auth() returned false. The Net::SMTP module has the set status line:
      $self->set_status(500, ["Need MIME::Base64 and Authen::SASL todo auth" +]), return 0;
      Why didn't the precise error message "Need MIME::Base64 and Authen::SASL todo auth" get to the end-user? Or what exactly should the user have done differently in the user-code to have gotten that precise, informative error message?
        Replace
        print "ERROR: Could not authenticate user $user_id\n$!\n";
        with
        print "ERROR: Could not authenticate user $user_id\n$: ".$mail->messa +ge."\n";
        or equivalent.
        Perhaps you should read my entire post instead of focusing on the rhetorical question. It explains why the message isn't returned via $!, and where it can be found.
Re: Error message not showing up from Net::SMTP
by syphilis (Archbishop) on Sep 05, 2007 at 15:01 UTC
    Net::SMTP's sub auth() begins as:
    . . sub auth { my (\$self, \$username, \$password) = \@_;
    Which version ? I find:
    sub auth { my ($self, $username, $password) = @_; . .
    And which version of perl ?

    Cheers,
    Rob
Re: Error message not showing up from Net::SMTP
by sg (Pilgrim) on Sep 05, 2007 at 15:30 UTC
    My mistake in the quote -- the cut and paste I used resulted in the extra '\'.
    perl -MNet::SMTP -e "print $Net::SMTP::VERSION" 2.31 Also, ppm query libnet reports libnet version as 1.22
      Aah ... and there's also an extraneous '\' before '$self'.

      As usual, I don't have a ready (and accurate) answer to your questions :-)

      Looks to me that set_status should have been called. Is set_status supposed to print an error message to stdout ? Where is set_status defined ? (Sheesh ... I hate inheritance ... )

      Cheers,
      Rob
Re: Error message not showing up from Net::SMTP
by sg (Pilgrim) on Sep 05, 2007 at 15:32 UTC
    Regarding perl version:
    Binary build 822 [280952] provided by ActiveState http://www.ActiveState.com Built Jul 31 2007 19:34:48

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://637170]
Approved by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2025-07-14 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.