Sending Bulk E-mails - Page 10
August 29, 2001
The last thing we need to do is send off the e-mails to all the
customers. We can reuse a slightly modified version of an earlier
script using the Mail::Send module.
use Mail::Send;
open(CSV,"newlist.txt") or die "Cannot open newlist.txt for read\n";
open(MESSAGE,"message.txt") or die "Cannot open message.txt for read\n";
my $message = join ('',<MESSAGE>);
while (<CSV>) {
my @list = split (/,/);
s/^"|"$//g foreach @list;
my $msg = new Mail::Send (To => "$list[0] $list[1] <$list[2]>",
Subject => "Recall: faulty coupling");
my $fh = $msg->open;
print $fh $message;
$fh->close;
}
Once the script has been run, each customer will receive the
following e-mail message:
|
We regret to inform you that due to a faulty internal
coupling in our new oscillation overthruster, you may experience
anomalies during molecular reconstruction due to leaking matter.
We highly recommend that you suspend operation of the drive until
an operative can replace the faulty part. We wish you success in
your travels to the eighth dimension and hope to see you soon on
Planet 10.
Sincerely,
John Wharfin
Yoyodyne Propulsion Systems
|
Conclusion
We've learned quite a bit about processing text with Perl
functions, how to utilize CSV files, and use array functions. In
the next and final article in the series, we'll learn more about
using pre-built Perl modules to make it even easier to perform
complex text processing tasks.
Sorting and Searching for Duplicate Records - Page 9
Weaving Magic With Regular Expressions
Processing Text with Perl Modules - Page 11
|