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
- use strict;
- use Fcntl;
- use Data::Dumper;
- use Mail::Sendmail;
- use MIME::QuotedPrint;
- use MIME::Base64;
- use HTML::Entities;
Expand|Select|Wrap|Line Numbers
- > Ambiguous use of % resolved as operator % at C:\BasicEmailBlaster.pl line 183.
- > Bareword "sendmail" not allowed while "strict subs" in use at C:\BasicEmailBlaster.pl line 183.
- > Bareword "mail" not allowed while "strict subs" in use at C:\BasicEmailBlaster.pl line 183.
- > Execution of C:\BasicEmailBlaster.pl aborted due to compilation errors.
Expand|Select|Wrap|Line Numbers
- sub SendEmail
- {
- my $bResult = 1;
- print "- SENDING CONFIRMATION EMAIL" . "\n";
- my $MAILLOG;
- print "- Attempting Open: " . '>> '. $MailLogFile ."\n";
- if ( ! open( MAILLOG, '>> '. $MailLogFile ) )
- {
- print "Failed to open Email Log!\n";
- print "- Attempting Open: " . '>> '. $LogFile ."\n";
- # log error message if not able to log email
- &LogIt("Can't Log Email>>\nCan't Open:\t" . $MailLogFile);
- undef $MAILLOG;
- }
- else
- {
- $MAILLOG = *MAILLOG;
- }
- if ( defined $MAILLOG )
- {
- print $MAILLOG (">> Mail Entry Start\n");
- }
- if ( !BuildEmail( \%mail ) )
- {
- print "Building the Email Failed!\n";
- if ( defined $MAILLOG )
- {
- print $MAILLOG (localtime( time ) . "\tBuilding the Email Failed!\n");
- &LogIt("Building the Email Failed!");
- }
- $bResult = 0;
- }
- else
- {
- print "- Attempting Sendmail!\n";
- 183 if (sendmail %mail)
- This is defining %mail
- sub BuildEmail
- {
- print "- BUILDING CONFIRMATION EMAIL" . "\n";
- my $OrderTxt = "";
- my $OrderHtm = "";
- for (my $i = 0; $i < 65; $i++)
- {
- $OrderTxt.= $EmailArrayTxt[$i];
- $OrderHtm.= $EmailArrayHtm[$i];
- }
- my ($MailHash) = shift;
- my %mail = %$MailHash;
- my $boundary = "====" . time() . "====";
- $MailHash->{From} = 'Me <me@none.com>';
- $MailHash->{To} = $To;
- $MailHash->{Bcc} = 'none@none.com';
- $MailHash->{smtp} = 'mail.mail.com';
- $MailHash->{subject} = "Subjects";
- $MailHash->{'content-type'} = "multipart/alternative; boundary=\"$boundary\"";
- local $/; # slurp mode (undef)
- local *F; # create local filehandle
- my $filename = 'C:\EmailBlasts\EmailTemplates\EmailBlast.txt';
- print "- Opening $filename\n";
- if ( !open(F, "<$filename") )
- {
- &LogIt("Can't Open:\t" . $filename);
- return 0;
- }
- my $tempText = <F>; # read whole file
- close(F); # ignore retval
- $tempText =~ s/%%Order%%/$OrderTxt/eg;
- my $plain = encode_qp $tempText;
- my $filename = 'C:\EmailBlasts\EmailTemplates\EmailBlast.html';
- print "- Opening $filename\n";
- if ( !open(F, "<$filename") )
- {
- &LogIt("Can't Open:\t" . $filename);
- return 0;
- }
- my $tempText = <F>; # read whole file
- close(F); # ignore retval
- $tempText =~ s/%%Order%%/$OrderHtm/eg;
- my $html = encode_qp $tempText;
- $MailHash->{body} = <<END_OF_BODY;
- --$boundary
- Content-Type: text/plain; charset="iso-8859-1"
- Content-Transfer-Encoding: quoted-printable
- $plain
- --$boundary
- Content-Type: text/html; charset="iso-8859-1"
- Content-Transfer-Encoding: quoted-printable
- $html
- --$boundary--
- END_OF_BODY
- }