CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Mail::Sender v0.8.2 throws error in debug mode only: Edit Log



bulrush
User

Jul 8, 2014, 9:31 AM


Views: 6758
Mail::Sender v0.8.2 throws error in debug mode only

  • Perl 5.8.8 on Linux RHEL 5.5.56
  • Mail::Sender v0.8.2
  • I need to send an email with Perl only, because I have not MTA, like sendmail, on my linux system. I need authentication, and the ability to send XLS attachments, so many other Perl modules do not work for me.
  • I'm trying to send an email, sometimes with an attachment, sometimes without. When not in debug mode, Mail::Sender works fine. When in debug mode, Mail::Sender often fails with the error below.
  • What this means is it's much harder to fix my Perl program because it doesn't work in debug mode.


    Code
    Can't call method "opened" without a package or object reference at (eval 97)[/usr/lib/perl5/site_perl/5.8.8/Mail/Sender.pm:359] line 46, <GEN8> line 1. 
    at (eval 97)[/usr/lib/perl5/site_perl/5.8.8/Mail/Sender.pm:359] line 46
    Mail::Sender::DBIO::opened('Mail::Sender::DBIO=GLOB(0xab581ec)') called at /usr/lib/perl5/site_perl/5.8.8/Mail/Sender.pm line 166
    Mail::Sender::send_cmd('Mail::Sender::DBIO=GLOB(0xab581ec)', 'EHLO myclient') called at /usr/lib/perl5/site_perl/5.8.8/Mail/Sender.pm line 203
    Mail::Sender::say_helo('Mail::Sender=HASH(0xaae58dc)', 'Mail::Sender::DBIO=GLOB(0xab581ec)') called at /usr/lib/perl5/site_perl/5.8.8/Mail/Sender.pm line 1070
    Mail::Sender::Connect('Mail::Sender=HASH(0xaae58dc)') called at /usr/lib/perl5/site_perl/5.8.8/Mail/Sender.pm line 1578
    Mail::Sender::OpenMultipart('Mail::Sender=HASH(0xaae58dc)', 'HASH(0xa98429c)') called at conv.pl line 704
    main::mailsender('My name <foo@somewhere.com>', 'out/GCADLP00001457out.xls', 'TEST: Your input file is done: GCADLP00001457.xls') called at conv.pl line 569
    main::proc1xls('My name <foo@somewhere.com>', 'ARRAY(0x97d7214)') called at conv.pl line 345
    main::getnetpop3b() called at conv.pl line 165
    Debugged program terminated. Use q to quit or R to restart,


  • Is this a known problem which will be fixed by an upgrade in Perl? We can't just upgrade anytime because it would take weeks to upgrade, then test about 100 Perl scripts.
    Upgrading is not done lightly.

    Subroutine below. Please note that this does not produce an error when not run in the debugger. Thus the reason I'm having so much trouble with this.


    Code
    #################################################################### 
    # Send one email for a test.
    # Uses Mail::Sender.
    # Jul 8, 2014. Try OpenMultipart() and Attach().
    sub mailsender
    {my($replyaddr,$fnout,$subjparam)=@_;
    my(@a,@b,$i,$j,$k,$procname,$result,$s,$t);
    my(%data,$body,$divline,$fileattach,$fn,$hashcnt,$key,$err,$sender,$to);
    my($prefixsp,$authuser,$authpw);

    $procname="mailsender";

    $prefixsp=' ';
    $authuser='auth@server.com'; # SMTP login name.
    $authpw='userpw';
    $fileattach=$fnout;
    # In testing mode the SMTP/outgoing To address is always xxx.
    if ($opttest eq '-test') # Command line option
    {
    $to='email@somewhere.com'; # DEBUG
    print $prefixsp."$procname: TEST: Swapping in $to for test address\n";
    }
    else {
    $to=$replyaddr; # Send email to this address.
    }
    if (len($to)<3) # Email must be at least n ctrs.
    {
    $s=$prefixsp."$procname ERROR: To address is missing.";
    writeerr($s);
    exit 1
    }

    $divline="========================================\r";

    $s=$prefixsp."$procname: Going to create Mail::Sender...";
    print "$s\n";
    $sender=new Mail::Sender
    ({
    on_errors=>'code',
    keepconnection=>1,
    debug=>'debugconv.txt',
    client=>'myclient',
    smtp=>'smtp.server.net',
    port=>80,
    from=>$authuser,
    authid=>$authuser,
    authpwd=>$authpw,
    auth=>'LOGIN'
    });
    if (($sender<0) or ($Mail::Sender::Error))
    {
    $s=$prefixsp."$procname ERROR: Could not make new Sender: '".$Mail::Sender::Error."'";
    writeerr($s);
    return;
    }

    # Line feeds for Outlook 2012 require \r.
    $body='';
    if ($opttest eq '-test') # Command line option
    {
    $body.="STILL IN TESTING MODE.\r";
    }
    if (len($fnout)>0)
    {
    $body.="Attached is your output file: $fnout.\r";
    }
    $body.="Log follows. Look for lines that say ERROR.\r";
    $body.=$divline;
    for ($i=0; $i<=$#errors; $i++)
    {
    $body.=$errors[$i]."\n";
    } # for i
    $body.=$divline;
    $body.="\r.\r"; # Required for email. Period on line by itself.
    $Mail::Sender::NO_X_MAILER='true'; # Omit X-Mailer info with machine info.

    if (len($fnout)>0)
    {
    if (-e $fnout) # If $fnout exists then...
    {
    # Will return negative number on error.
    # Sometimes this doesn't work.
    @a=split('/',$fnout);
    $fn=$a[$#a]; # Drop directories from $fnout.
    print $prefixsp."$procname: Attaching file: $fileattach\n";
    $result=0;
    # Was $result=$sender->MailFile(...)
    $result=$sender->OpenMultipart(
    {
    #file=>$fileattach,
    to=>$to,
    subject=>$subjparam,
    msg=>$body,
    });
    if (($result<0) )
    {
    $s=$prefixsp."$procname ERROR: ".
    "$result on OpenMultipart(): '".
    trim($Mail::Sender::Error)."'\n";
    writeerr($s);
    $sender->Close();
    exit 1;
    }

    $result=$sender->Attach({
    description=>$fn,
    ctype=>'application/vnd.ms-excel',
    encoding=>'Base64',
    file=>$fileattach,
    disposition=>"attachment; filename=$fn"
    });
    if (($result<0) )
    {
    $s=$prefixsp."$procname ERROR: ".
    "$result on Attach(): '".
    trim($Mail::Sender::Error)."'\n";
    writeerr($s);
    $sender->Close();
    exit 1;
    }
    }
    else {
    $s=$prefixsp."$procname ERROR: $fnout does not exist.";
    writeerr($s);
    $sender->Close();
    exit 1;
    }
    }
    else {
    # Do not send file, send error msg only.
    $s=$prefixsp."$procname: Going to do simple email...";
    print "$s\n"; # DEBUG
    $result=$sender->Open({to=>$to, subject=>$subjparam});
    if ($result<0)
    {
    $s=$prefixsp."$procname ERROR: on simple Open: '".
    trim($Mail::Sender::Error)."' \n";
    writeerr($s);
    $sender->Close();
    exit 1;
    }
    $result=$sender->SendLineEnc($body);
    if ($result<0)
    {
    $s=$prefixsp."$procname ERROR: on simple SendLineEnc: '".
    trim($Mail::Sender::Error)."' \n";
    writeerr($s);
    $sender->Close();
    exit 1;
    }
    }

    # Now close connection.
    $sender->Close();
    if ($@)
    {
    $s=$prefixsp."$procname ERROR: Could not make new Mail::Sender. $@";
    writeerr($s);
    exit 1;
    }
    else {
    $s=$prefixsp."$procname: Sent email to $to";
    if (len($fnout)>0)
    {
    $s.=" with file $fnout";
    }
    writeerr($s);
    }

    return; # mailsender
    }

    -----


    (This post was edited by bulrush on Jul 9, 2014, 3:52 AM)


  • Edit Log:
    Post edited by bulrush (User) on Jul 9, 2014, 3:25 AM
    Post edited by bulrush (User) on Jul 9, 2014, 3:28 AM
    Post edited by bulrush (User) on Jul 9, 2014, 3:41 AM
    Post edited by bulrush (User) on Jul 9, 2014, 3:52 AM


    Search for (options) Powered by Gossamer Forum v.1.2.0

    Web Applications & Managed Hosting Powered by Gossamer Threads
    Visit our Mailing List Archives