Description: |
An old script I wrote about a year ago.
Not very elegant but gets the job done.
Sending out seemingly personalized letters to a list of people.
It takes a couple of files:
A data file that looks like:
EMAIL|REALNAME
bob@blah.com|Bob Blah
george@blah.com|George Blah
It needs an EMAIL column so it knows where to send the mail to
the rest of the columns are up to you. Column headers and row
data are separated by |'s
Then you just make a message file like so and it makes the
necessary substitutions:
Dear REALNAME,
Your e-mail address is: EMAIL
Love,
Your Mom
|
#!/usr/bin/perl
print "Form Mailer 0.1\n";
print "Where's your data file?\n";
$datafile=<>;
print "What's the subject of your message?\n";
$subject=<>;
print "Who do you want the message to be from? (your e-mail)\n";
$from=<>;
print "Where's the message located?\n";
$messageloc= <>;
chomp($from,$messageloc,$datafile);
open MESSAGE,"<$messageloc";
$messagebody=join '', <MESSAGE>;
close MESSAGE;
open DATA, "<$datafile";
$header=<DATA>;
chomp $header;
@header=split(/\|/,$header);
while($line=<DATA>){
chomp $line;
@linesplit=split(/\|/,$line);
for(my $i=0; $i<@header; $i++){
$header{$header[$i]}=$linesplit[$i];
}
$message=$messagebody;
foreach(keys %header){
print "key $_ => $header{$_}\n";
$message=~s/$_/$header{$_}/g;
}
open(MAIL, "|/usr/lib/sendmail -oem -t -oi");
print MAIL "From: $from\n";
print MAIL "To: $header{EMAIL}\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message\n";
close MAIL;
}
close DATA;
|