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

 



bulrush
Novice

Jul 8, 2014, 9:31 AM

Post #1 of 5 (3962 views)
Mail::Sender v0.8.2 throws error in debug mode only Can't Post

  • 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
    }

    -----
    * Redhat Linux RHEL 5.5.56
    * Perl 5.8.8

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


  • Laurent_R
    Veteran / Moderator

    Jul 8, 2014, 10:00 AM

    Post #2 of 5 (3960 views)
    Re: [bulrush] Mail::Sender v0.8.2 throws error in debug mode only [In reply to] Can't Post

    Please show your code, we can't say anything without seeing it.


    bulrush
    Novice

    Jul 9, 2014, 3:41 AM

    Post #3 of 5 (3372 views)
    Re: [Laurent_R] Mail::Sender v0.8.2 throws error in debug mode only [In reply to] Can't Post

    Added code of subroutine above. Thanks.
    -----
    * Redhat Linux RHEL 5.5.56
    * Perl 5.8.8


    wickedxter
    User

    Jul 19, 2014, 9:05 PM

    Post #4 of 5 (1837 views)
    Re: [bulrush] Mail::Sender v0.8.2 throws error in debug mode only [In reply to] Can't Post


    Code
    open my $DEBUG, ">> /path/to/debug/file.txt" 
    or die "Can't open the debug file: $!\n"
    $sender = new Mail::Sender ({
    ...
    debug => $DEBUG,
    });


    its looks like the $DEBUG need to be a file glob ref for debug to work as in the pod for the module.

    you just have a file name.


    (This post was edited by wickedxter on Jul 19, 2014, 9:05 PM)


    FishMonger
    Veteran / Moderator

    Jul 20, 2014, 8:57 AM

    Post #5 of 5 (1816 views)
    Re: [wickedxter] Mail::Sender v0.8.2 throws error in debug mode only [In reply to] Can't Post


    In Reply To

    Code
    open my $DEBUG, ">> /path/to/debug/file.txt" 
    or die "Can't open the debug file: $!\n"
    $sender = new Mail::Sender ({
    ...
    debug => $DEBUG,
    });


    its looks like the $DEBUG need to be a file glob ref for debug to work as in the pod for the module.

    you just have a file name.


    You forgot to include the text describing the usage of the debug parameter, which says you can pass a filename.


    Quote
    debug

    => "/path/to/debug/file.txt"

    or

    => \*FILEHANDLE

    or

    => $FH

    All the conversation with the server will be logged to that file or handle. All lines in the file should end with CRLF (the Windows and Internet format). If even a single one of them does not, please let me know!

    If you pass the path to the log file, Mail::Sender will overwrite it. If you want to append to the file, you have to open it yourself and pass the filehandle:


    To bulrush:
    If the error only show up when you enable debug on the object, then I'd say the module may have a bug. I see that the author uploaded a new version ( 0.8.23 ) on the 15th. Start by upgrading to that version and pass a filehandle instead of just the filename to rule out an issue with the module opening the filehandle. If you still have the same problem, then contact the author and/or submit a bug report.


    (This post was edited by FishMonger on Jul 20, 2014, 9:04 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