By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,777 Members | 1,755 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,777 IT Pros & Developers. It's quick & easy.

Mail:SendMail Troubleshooting

P: 3
Hi I am new here and once upon a time I worked with Perl, now I am trying again and need some help:

I wrote a Perl script a few years ago that opened an order entry TXT file and sent each customer with an email address a confirmation email in html or txt. Simple enough and very effective.

Now I am editing this script to send a general email blast on a new computer... I have ActivePerl 5.10.0 Build 1003 installed. I downloaded Mail:Sendmail and put SendMail.pm in C:\Perl\lib\Mail

First, I have a question about Perl and Mail:SendMail installation:

I am not sure that's all I have to do to install SendMail.pm right. For example, it doesn't show up in the Perl Package Manager from ActivePerl. If I view all packages and go to Mail:SendMail and select Install it warns me: WARNING: Installing Mail-Sendmail-0.79 would downgrade Mail::Sendmail from version 2.09 to 0.79

So I assume that the new version I dropped in lib\Mail 2.09 is installed.

???? right ????

I downloaded a trial version of Komodo IDE 4.4 to do my editing and debugging. Curious, what applications do people here recommend?

I made some edits to the script that basically remove the array looking for order details. My new email blast TXT is a simple tab delimited format: name (tab) email address (eol).

I am getting an error at the SendMail line. Here are some details...

Here's the opening of the file:

Expand|Select|Wrap|Line Numbers
  1. use strict; 
  2. use Fcntl; 
  3. use Data::Dumper; 
  4. use Mail::Sendmail; 
  5. use MIME::QuotedPrint; 
  6. use MIME::Base64; 
  7. use HTML::Entities; 
Here are the errors from the debugger:
Expand|Select|Wrap|Line Numbers
  1. > Ambiguous use of % resolved as operator % at C:\BasicEmailBlaster.pl line 183. 
  2.  
  3. > Bareword "sendmail" not allowed while "strict subs" in use at C:\BasicEmailBlaster.pl line 183. 
  4.  
  5. > Bareword "mail" not allowed while "strict subs" in use at C:\BasicEmailBlaster.pl line 183. 
  6.  
  7. > Execution of C:\BasicEmailBlaster.pl aborted due to compilation errors. 
Here is the Sub leading up to the Error - Error is on line 183 - the last line below:

Expand|Select|Wrap|Line Numbers
  1. sub SendEmail 
  2. my $bResult = 1; 
  3.  
  4. print "- SENDING CONFIRMATION EMAIL" . "\n"; 
  5.  
  6. my $MAILLOG; 
  7.  
  8. print "- Attempting Open: " . '>> '. $MailLogFile ."\n"; 
  9.  
  10. if ( ! open( MAILLOG, '>> '. $MailLogFile ) ) 
  11. print "Failed to open Email Log!\n"; 
  12. print "- Attempting Open: " . '>> '. $LogFile ."\n"; 
  13.  
  14. # log error message if not able to log email 
  15. &LogIt("Can't Log Email>>\nCan't Open:\t" . $MailLogFile); 
  16. undef $MAILLOG; 
  17. else 
  18. $MAILLOG = *MAILLOG; 
  19.  
  20. if ( defined $MAILLOG ) 
  21. {    
  22. print $MAILLOG (">> Mail Entry Start\n"); 
  23.  
  24. if ( !BuildEmail( \%mail ) ) 
  25. print "Building the Email Failed!\n"; 
  26. if ( defined $MAILLOG ) 
  27. {    
  28. print $MAILLOG (localtime( time ) . "\tBuilding the Email Failed!\n"); 
  29. &LogIt("Building the Email Failed!"); 
  30. $bResult = 0; 
  31. else 
  32. print "- Attempting Sendmail!\n"; 
  33.  
  34. 183     if (sendmail %mail) 
  35.  
  36. This is defining %mail
  37.  
  38. sub BuildEmail
  39. {
  40.     print "- BUILDING CONFIRMATION EMAIL" . "\n";
  41.  
  42.     my $OrderTxt = "";
  43.     my $OrderHtm = "";
  44.     for (my $i = 0; $i < 65; $i++)    
  45.     {
  46.         $OrderTxt.= $EmailArrayTxt[$i];
  47.         $OrderHtm.= $EmailArrayHtm[$i];
  48.     }
  49.  
  50.     my ($MailHash) = shift;
  51.     my %mail = %$MailHash;
  52.     my $boundary = "====" . time() . "====";
  53.  
  54.     $MailHash->{From}    = 'Me <me@none.com>';
  55.     $MailHash->{To}      = $To;
  56.     $MailHash->{Bcc}     = 'none@none.com';
  57.     $MailHash->{smtp}    = 'mail.mail.com';
  58.     $MailHash->{subject} = "Subjects";
  59.     $MailHash->{'content-type'} = "multipart/alternative; boundary=\"$boundary\"";
  60.  
  61.     local $/;                   # slurp mode (undef)
  62.     local *F;                   # create local filehandle
  63.  
  64.     my $filename = 'C:\EmailBlasts\EmailTemplates\EmailBlast.txt';
  65.  
  66.     print "- Opening $filename\n";
  67.     if ( !open(F, "<$filename") )
  68.     {
  69.         &LogIt("Can't Open:\t" . $filename);
  70.         return 0;    
  71.     }
  72.  
  73.     my $tempText = <F>;         # read whole file
  74.     close(F);                   # ignore retval
  75.  
  76.     $tempText =~ s/%%Order%%/$OrderTxt/eg;
  77.  
  78.     my $plain = encode_qp $tempText;
  79.  
  80.     my $filename = 'C:\EmailBlasts\EmailTemplates\EmailBlast.html';
  81.  
  82.     print "- Opening $filename\n";
  83.     if ( !open(F, "<$filename") )
  84.     {
  85.         &LogIt("Can't Open:\t" . $filename);
  86.         return 0;    
  87.     }
  88.  
  89.     my $tempText = <F>;            # read whole file
  90.     close(F);                   # ignore retval
  91.  
  92.     $tempText =~ s/%%Order%%/$OrderHtm/eg;
  93.  
  94.     my $html = encode_qp $tempText;
  95.  
  96.  
  97. $MailHash->{body} = <<END_OF_BODY;
  98. --$boundary
  99. Content-Type: text/plain; charset="iso-8859-1"
  100. Content-Transfer-Encoding: quoted-printable
  101.  
  102. $plain
  103.  
  104. --$boundary
  105. Content-Type: text/html; charset="iso-8859-1"
  106. Content-Transfer-Encoding: quoted-printable
  107.  
  108. $html
  109.  
  110. --$boundary--
  111. END_OF_BODY
  112.  
  113. }
  114.  
Any Ideas
Sep 4 '08 #1
Share this Question
Share on Google+
3 Replies


P: 3
Okay, I solved my problem by installing the Mail:SendMail 0.79 against PPMs advice. Now I need to add SMTP Authentication to my code. My new server authenticates, how do I do that?

Here's what I have now:

My settings:
Expand|Select|Wrap|Line Numbers
  1. $MailHash->{From} = '**@***.com'; 
  2. $MailHash->{To} = $To; 
  3. $MailHash->{Bcc} = '**@***.com'; 
  4. $MailHash->{smtp} = 'mail.mail.com'; 
  5. $MailHash->{subject} = "Newsletter"; 
  6. $MailHash->{'content-type'} = "multipart/alternative; boundary=\"$boundary\"";
Sep 4 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
As suggested on perlguru, you may need to switch to Net::SMTP. The module you are using does not appear to support authentication.
Sep 4 '08 #3

P: 3
aww you're everywhere. thanks.
Sep 5 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.