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

Is it possible to retrieve the mailserver's response to each command when using Net::SMTP? Here is basically what I want to do:

my $smtp; $smtp = Net::SMTP->new( $mailhost, Timeout =} $tmout ); {print server response here} $smtp->mail( $fromaddr ); {print server response here} $smtp>to( $recip ); {print server response here} $smtp>data(); {print server response here} $smtp>datasend( "To: $recip\n" ); $smtp>datasend( "From: $fromaddr\n" ); $smtp>datasend( "Subject: $subject\n" ); $smtp>datasend( "\n" ); $smtp>datasend( "$body\n" ); $smtp>dataend(); {print server response here} $smtp>quit;

I know I can get the success or failure of each command like this:

$response=$smtp->mail( $fromaddr ); print "$response\n";
but I want to retrieve the actual reply code that the server returns. Any suggestions?

InsolentFlunkey

Replies are listed 'Best First'.
Re: Retrieving server response with Net::SMTP
by count0 (Friar) on Aug 31, 2001 at 22:14 UTC
    You can give the methods from Net::Cmd a try.
    It is inherited by Net::SMTP.

    Specifically, message(), code(), and status() should be the most useful.