in reply to Problems using Mail::Sender

You need to check to make sure that the object is created and that the message opens successfully. Try this:
my $sender; unless(ref($sender = new Mail::Sender { 'smtp' => $mail_server, 'from' => $id, 'auth' => 'CRAM-MD5', 'authid' => $id, 'authpwd' => $pswd, 'subject' => 'Birthday invitation', 'boundary' => 'A boring Multipart bou +ndary', 'multipart' => 'mixed', 'encoding' => 'Quoted-printable', 'confirm' => 'reading', 'keepconnection' => 'true'})) { die "Creating obejct failed: $Mail::Sender::Error\n"; }
You also need to check the OpenMultipart call for errors.

You should always write your code as if every part of it will break, because unless you live in a perfect world, it probably eventually will.

Replies are listed 'Best First'.
Re: Re: Problems using Mail::Sender
by Jenda (Abbot) on Aug 22, 2003 at 18:40 UTC

    :-)
    You can also instruct the newest versions of Mail::Sender to throw an exception (die()) in case of errors. I guess that's a bit safer and easier since then you do not have to worry about each and every method call and just catch the exception where it makes most sense:

    eval { my $sender = new Mail::Sender { 'on_errors' => 'die', 'smtp' => $mail_server, 'from' => $id, 'auth' => 'CRAM-MD5', 'authid' => $id, 'authpwd' => $pswd, 'subject' => 'Birthday invitation', 'boundary' => 'A boring Multipart boundary', 'multipart' => 'mixed', 'encoding' => 'Quoted-printable', 'confirm' => 'reading', 'keepconnection' => 'true'}); $sender->OpenMultipart(...); $sender->Part(...); ... }; if ($@) { print "Failed to sent the message: $@\n"; } ...

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Re: Re: Problems using Mail::Sender
by CombatSquirrel (Hermit) on Aug 22, 2003 at 17:15 UTC
    Thanks for your tip, I should've known it (I learned it that way, after all :-). Anyways, the main problem turned out to be that the $mail_server variable was somehow affected; I replaced it by a constant string and everything worked. I also spotted some beginner's mistakes in my code, such as not escaping the square brackets. Everything is fixed now and I should be able to do the rest on my own.
    Thanks, all.