Mail::Sender - How to Check Result Code?

I have a code block which sends a mail using Mail::Sender. Everything works great now. I just want to know how to check whether the status of sending mail is success or failure. Based on which I will log the result in my log file.

How can I do this? Any idea please?

Try the docs

1 Like

I tried this code

#!/usr/bin/perl

sub BEGIN {
        unshift (@INC,'/opt/dev/common/mds/perlLib');
}

use Mail::Sender;

$sender = new Mail::Sender {
smtp => 'xxx.xxx.x.xx',
from => 'abc@xyz.com',
on_errors => 'code',
};
die "Can't create the Mail::Sender object: $Mail::Sender::Error\n" unless ref $sender;
ref $sender->Open({
to => 'bkannan@inautix.co.in',
cc => 'bkannan@inautix.co.in',
subject => 'Sorry, I\'ll come later.'
})
or die "Can't open the message: $sender->{'error_msg'}\n";
$sender->SendLineEnc("I'm sorry, but thanks to the lusers, I'll come at 10pm at best.");
$sender->SendLineEnc("\nHi, Jenda");
ref $sender->Close or die "Failed to send the message: $sender->{'error_msg'}\n";

The message is successfully sent. I received it. However it outputs

Does it mean it fails at $sender->close? I don't get it sorry! Somebody please explain and how can I resolve it?