################### GET THE DATABASE USERNAME & PASSWORD TO CONNECT TO THAT DATABASE ######################### #$sel_dbinfo=$db->prepare("select Ip_address,Db_usname,Db_pass from Herald_Companies where Company_id=$cpcode"); #$sel_dbinfo->execute; #($ip_address,$db_name,$db_pass)=$sel_dbinfo->fetchrow_array; #$acc_db = DBI->connect("DBI:mysql:$db_name:$ip_address",$db_name,$db_pass); $acc_db = DBI->connect("DBI:mysql:$dbname:$ipadd",$dbname,$dbpass); $folder_name = "$send_date"."$send_mon"."$send_year"; ######## used to save the details in this folder $sign = "

$signature_contents
"; #--------- check if the mail is to be sent today or later -----------# if($send_date == $ind_day && $send_mon == $ind_mon && $send_year == $ind_year) { $mail_time=0; } else { $mail_time = 1; } #print"Mail_time = $mailtime
"; #print"Mailtype = $mailtype
"; ################ GET THE RECiPIENTS ################################# ############## OPTION 1 ############################################ ########### IF OPTION IS KEY IN ADDRESS ############################# if($choice == 1) { $all_emails = $query->param('recepient'); #-------- recipients ----------------# @test_recipients = split(",",$all_emails); $tot_rec = $#test_recipients + 1; ########### TOATL NO OF RECEPIENTS TO WHOM MAIL SHOULD BE SENT &check_emails($tot_rec,$email_shot); ################## CHECK FOR THE NO OF RECEPIENTS TO BE SENT AT 1 SHOT ########################## foreach $ids(@test_recipients) { if($ids =~ "(.*)\@(.*)\.") { #print "ok"; push(@recepientid,$ids); } else { push(@invalid_ids,$ids); } } } ############## END OF OPTION 1 ############################################ ############## OPTION 2 ############################################ ########### IF OPTION IS ALL MEMBERS IN ADDRESS BOOK ############################# if($choice == 2) { $sel_ids=$acc_db->prepare("select a.User_Id,a.Name,a.Nickname,a.Company,b.Email from $cpcode"."_Address a,Email b where a.User_Id=b.User_Id"); $sel_ids->execute; while(($db_user,$db_name,$db_nick,$db_company,$db_email)=$sel_ids->fetchrow_array) { #print"$db_user,$db_name,$db_nick,$db_company,$db_email
"; push(@dbuser,$db_user); push(@dbname,$db_name); push(@dbnick,$db_nick); push(@dbcompany,$db_company); push(@recepientid,$db_email); } } ############## END OF OPTION 2 ############################################ ############## OPTION 3 ############################################ ########### IF OPTION IS ALL MEMBERS FROM SELECTED OPTION ############################# if($choice == 3) { ########### READ QUERY.TXT FILE ########### # open(FILE,"$basedir/jayanthra/admin/sendmail/query.txt") or die "Can't Open File"; open(FILE,"$sendmaildir/$cpcode/query.txt") or die "Can't Open File"; while(read(FILE,$buffer,1024)) { $query1.=$buffer; } close(FILE); #$query1 = chop($query); #print "QUERY1 - $query1
"; #$query1=urldecode($query1); $sel_ids=$acc_db->prepare("$query1"); $sel_ids->execute; while(($db_user,$db_name,$db_nick,$db_company)=$sel_ids->fetchrow_array) { $sel_email=$db->prepare("select Email from $cpcode"."_Email where User_Id='$db_user'"); $sel_email->execute; while(($db_email)=$sel_email->fetchrow_array) { #print"$db_user,$db_name,$db_company,$db_email
"; push(@dbuser,$db_user); push(@dbname,$db_name); push(@dbnick,$db_nick); push(@dbcompany,$db_company); push(@recepientid,$db_email); } } } ############## END OF OPTION 3 ############################################ ############## OPTION 4 ############################################ ########### IF OPTION IS SELECTED MEMBERS FROM SELECTED OPTION ############################# if($choice == 4) { ########### GET user id and EMAIL IDS FROM THE LIST BOX ########### @selected_recipients = $query->param('email_select'); #-------- recipients ----------------# print "SELECTED RECE - @selected_recipients
"; exit; &check_emails($tot_rec,$email_shot); #-------- contains the user id and email, split to get them seperately ---------- foreach $selected_email(@selected_recipients) { @split_items=split("~",$selected_email); #print "@split_items
"; #----Get the name and company of selected emails using the user id ----------- $sel_email=$acc_db->prepare("select Name,Nickname,Company from $cpcode"."_Address where User_Id='$split_items[0]'"); $sel_email->execute; ($db_name,$db_nick,$db_company)=$sel_email->fetchrow_array; #print"$split_items[0],$db_name,$db_company,$split_items[1]
"; push(@dbuser,$split_items[0]); push(@dbname,$db_name); push(@dbnick,$db_nick); push(@dbcompany,$db_company); push(@recepientid,$split_items[1]); } } ############## END OF OPTION 4 ############################################ ################# CHECK IF UNSUBSCRIBE IS TO BE SENT ############## $unsubscribe = $query->param('unsubscribe'); ############## GET THE MAIL ID OF THE ADMIN FROM THE SIGNATURE FOLDER ########### push(@recepientid,$admin_email); # foreach $test(@recepientid) # { # print "Rece - $test
"; # } #print "HTMLMAIL -- $htmlmail
"; #print "mail type = $mailtype"; ############# WRITE ALL THE SELECTED RECEPIENT EMAIL IDS INTO A TEXT FILE ############## #foreach $recip_id(@recepientid) #{ #$format_reci.="$recip_id"."&"; #} #$format_reci.="^"."$Name"."^"."$sender"."^"."$subject"; #open(EMAILLOG,">$basedir/admin/herald/emails.txt") || die "error"; #print EMAILLOG $format_reci; #close(EMAILLOG); ############ IF THE MAIL HAS TO BE SENT IN A LATER DATE ######## if($mail_time == 1) { require "herald_sendmail_later.pl"; exit; } ############# IF HTML MAIL TO BE SENT ################################## if($htmlmail == 1) { $draft_name = $query->param('html_draft'); #-------- Draft name-------------# #print "DRAFT NAME - $draft_name
"; #print "started calling the HTML Mailer
"; require "herald_send_htmlmail.pl"; #print "Location: http://www.angleritech.com/admin/herald/send_html.shtml\n\n"; exit; } ######### IF DRAFTED MAIL ########################################## elsif($mailtype) { #print "started calling the Drafted Mailer
"; require "herald_send_dmail.pl"; exit; } ######### IF NEW MAIL ########################################## else { print "OK - New Mail"; #require "herald_send_cmail.pl"; exit; } sub check_emails { my $tot_rec=$_[0]; my $email_shot=$_[1]; if($tot_rec >= $email_shot) { print "Cannot send mails to $tot_rec email ids at 1 shot"; exit; } }