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

Hello - I am new here and have only limited Perl experience. I have spent about four hours trying to find a solution to a simple problem I have with MIME::Lite. I just need a pointer, not lots of hand holding :-) I'm using the brilliant MIME::Lite for sending mail and congratulate the author. However, I have a simple problem to overcome when using SMTP. It will easily give me SMTP Error that it comes across (5xx) for parsing, but I would like to get the remote server response line when it is successful (such as 250 OK message queued for delivery ABABABAB etc)
sub sendmsg { my $mx_record = shift; my $sender = shift; my $recipient = shift; my $subject = shift; my $messagebody = shift; my $message; my $result; $message = MIME::Lite->new( Subject => $subject, To => $recipient, From => $sender, Type => 'text/html', Data => $messagebody ); $message->replace("X-Mailer" => "Perl Mailer Override"); $message->add("X-Antiabuse" => ["anti abuse tracking", "cid:12 +34", "ccid:5678"]); MIME::Lite->send('smtp', $mx_record, Hello => 'example.com', T +imeout => 20); # Send the message eval{$message->send}; if($@) { $result = "ERROR from MX: $mx_record\n$@\n"; } else { $result = "OK from MX: $mx_record\n"; } return $result; }
My basic problem that I seek wisdom with is, how do I get at the successful server response? Warm and kind regards Leslie

Replies are listed 'Best First'.
Re: MIME::Lite 250 OK QUEUE ID???
by ig (Vicar) on Oct 15, 2010 at 15:23 UTC

    I don't think MIME::Lite provides access to the messages from the server on successful delivery.

    I have used Net::SMTP directly to send simple messages. This gives access to all the replies from the SMTP server but it requires you to deal with all the details. Your example looks simple enough that it might be sufficient.

    Otherwise, I have used MIME::Tools to compose and send multi-part messages. If this doesn't give access to success messages (I don't know off-hand), you could use it to compose the message then use Net::SMTP to send it.

Re: MIME::Lite 250 OK QUEUE ID???
by Anonymous Monk on Oct 15, 2010 at 10:56 UTC
    # Send the message eval{$message->send};
    Why eval? The documentation shows
    $msg->send || die "you DON'T have mail!";
    It also says After sending, the method last_send_successful() can be used to determine if the send was succesful or not.
      Err, eval because I don't want it to die if it fails - I want to process the error. I don't know any other way being a novice :-) I have found, however, that and using die, funny enough, stops execution which is not the course of action I would like. I did look at last_send_successful() but my feeble attempts gained me: "Can't locate object method "last_send_successful" via package "MIME::Lite"" thus:
      eval{$message->send}; if($@) { $result = "ERROR from MX: $mx_record\n$@\n"; } else { $result = $message->last_send_successful(); }
        The documentation implies that send will not die on failure, that it will simply return false, so
        $message->send or do_something(); $message->send; if( ! $message->last_send_successful ){ $ERROR = "ERROR from MX: $mx_record\n"; }
        If indeed send might die, the documentation needs updating (file a bug report).

        "Can't locate object method "last_send_successful" via package "MIME::Lite"

        Install the latest MIME::Lite