Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use MIME::Lite::TT::HTML;
- use LWP::Simple;
- use Text::CSV_XS;
- use Date::Format;
- use DBI;
- require "/home/user/emailservice/functions.pl";
- my $ccemailcount = 0;
- my $ccemaillist;
- my $emailcount = 0;
- my $emaillist;
- # constant contact variables
- my $list_id = 1;
- ####################################
- my $today = time2str("%Y-%m-%d",time);
- my $timebetweensends = 7 * 24 * 60 * 60;
- my $timecheck = time();
- my $url = 'http://mail.domain.com:8000/asptest.asp';
- my $file = '/home/user/emailservice/log_thankyou/thankyou'.$today.'.txt';
- my $content = getstore($url,$file);
- die "Couldn't get it!" unless defined $content;
- my $table = "log";
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
- # choose email template
- $textemailtemplate = "default.txt.tt";
- $htmlemailtemplate = "default.html.tt";
- $dbh = DBI->connect ("DBI:CSV:f_dir=/home/user/emailservice");
- # open csv file that holds today's content
- my $csv = Text::CSV_XS->new ({ binary => 1, sep_char => "|" });
- open my $fh, "<", $file or die "$file: $!";
- while (my $row = $csv->getline ($fh)) { #read a line from the csv file
- my ($firstname, $lastname) = FixNames(@$row[0]);
- my $emailaddress = @$row[1];
- my $lastin = @$row[3];
- my $subject = "Thank You ".$firstname;
- ($ccemailcount, $ccemaillist) = ConstantContact($emailaddress, $firstname, $lastname, $list_id, $ccemailcount, $ccemaillist);
- # check the log to see if this person has ben emailed in the last 7 days
- my $query = "SELECT email, timestamp, lastin FROM $table WHERE email = ". $dbh->quote ($emailaddress)." AND lastin = ". $dbh->quote ($lastin);
- my $sth = $dbh->prepare ($query);
- $sth->execute ();
- while (my $query_row = $sth->fetchrow_hashref) {
- if ( ($query_row->{timestamp} > 0) ) { #do nothing
- } else {
- my %params;
- $params{first_name} = $firstname;
- $params{last_name} = $lastname;
- my %options;
- $options{INCLUDE_PATH} = '/home/user/emailservice/emailtemplates';
- $emailaddress = "email\@domain.biz";
- my $msg = MIME::Lite::TT::HTML->new(
- To => $emailaddress,
- Subject => $subject,
- Template => {
- text => $textemailtemplate,
- html => $htmlemailtemplate,
- },
- TmplOptions => \%options,
- TmplParams => \%params,
- );
- $msg->send;
- $emailcount ++;
- $emaillist .= $firstname." ".$lastname."\n";
- $dbh->do ("INSERT INTO $table VALUES (". $dbh->quote (time()) .",". $dbh->quote ($firstname).",". $dbh->quote ($lastname). ",". $dbh->quote ($emailaddress) .",". $dbh->quote ($today) .",". $dbh->quote ($lastin).")");
- my $msg = MIME::Lite::TT::HTML->new(
- Subject => $subject,
- Template => {
- text => $textemailtemplate,
- html => $htmlemailtemplate,
- },
- TmplOptions => \%options,
- TmplParams => \%params,
- );
- # $msg->send;
- }
- }
- $sth->finish ();
- }
- csv->eof or $csv->error_diag;
- close $fh or die "file.csv: $!";
- printf "%d Thank You Email(s) were sent, and %d addresses were added to Constant Contact\n",$emailcount, $ccemailcount;
- if ($emailcount > 0) { printf "Emails were sent to:\n================================\n%s", $emaillist; }
- if ($ccemailcount > 0) { printf "Constant Contact Additions:\n==========================\n%s",$ccemaillist; }
- exit;
Advertisement
Add Comment
Please, Sign In to add comment