Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Form Mailer

by vroom (Pope)
on Jan 28, 2000 at 01:14 UTC ( #2515=sourcecode: print w/ replies, xml ) Need Help??

Category: E-mail
Author/Contact Info vroom vroom@cs.hope.edu
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;

Comment on Form Mailer
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://2515]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-12-27 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls