[Vtigercrm-developers] SendReminder Refactor (diff patch)

MAGGI Conrado comaggi at gmail.com
Thu Sep 11 09:14:16 GMT 2014


Hi.

The send reminder service does not work when you use tls smtp servers.
Debugging the issue I found that its possible to use the function
setMailerProperties from Emails module. This function works fine using tls
and save a few lines of codes in the send reminder files.

Please find attach the diff file.

Regards,
Conrado
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20140911/7847735d/attachment-0001.html>
-------------- next part --------------
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- <html>SendReminder.service (<b>28/07/2014 15:08:57</b>)</html>
+++ <html><b>Current File</b></html>
@@ -29,13 +29,15 @@
 
 $current_user = Users::getActiveAdminUser();
 // Set the default sender email id
-global $HELPDESK_SUPPORT_EMAIL_ID;
+global $HELPDESK_SUPPORT_EMAIL_ID,$HELPDESK_SUPPORT_NAME;
 $from = $HELPDESK_SUPPORT_EMAIL_ID;
 if(empty($from)) {
 	// default configuration is empty?
 	$from = "reminders at localserver.com";
 }
 
+$from_name = $HELPDESK_SUPPORT_NAME;
+
 // Get the list of activity for which reminder needs to be sent
 
 global $adb;
@@ -140,7 +142,8 @@
 							$app_strings['Visit_Link']." <a href='".$site_URL."/index.php?view=Detail&module=Calendar&record=".$activity_id."'>".$app_strings['Click here']."</a>";
 			if(count($to_addr) >=1)
 			{
-				send_email($to_addr,$from,$subject,$contents,$mail_server,$mail_server_username,$mail_server_password);
+				$status = send_email($to_addr,$from,$from_name,$subject,$contents);
+                                if($status == '1'){
 				$upd_query = "UPDATE vtiger_activity_reminder SET reminder_sent=1 where activity_id=?";
 				$upd_params = array($activity_id);
 
@@ -151,6 +154,7 @@
 				}
 
 				$adb->pquery($upd_query, $upd_params);
+                                }
 
 			}
 		}
@@ -169,56 +173,19 @@
 	$mail_server_password as string - sendmail server password
 
 */
-function send_email($to,$from,$subject,$contents,$mail_server,$mail_server_username,$mail_server_password)
+function send_email($to,$from,$from_name,$subject,$contents)
 {
-	global $adb;
-	 global $log;
+	global $adb, $log;
         $log->info("This is send_mail function in SendReminder.php(vtiger home).");
-	global $root_directory;
 
 	$mail = new PHPMailer();
 
+        setMailerProperties($mail, $subject, $contents, $from, $from_name, $to);
 
-	$mail->Subject = $subject;
-	$mail->Body    = nl2br($contents);//"This is the HTML message body <b>in bold!</b>";
-
-
-	$mail->IsSMTP();                                      // set mailer to use SMTP
-
-		$mailserverresult=$adb->pquery("select * from vtiger_systems where server_type='email'", array());
-		$mail_server = $adb->query_result($mailserverresult,0,'server');
-		$mail_server_username = $adb->query_result($mailserverresult,0,'server_username');
-		$mail_server_password = $adb->query_result($mailserverresult,0,'server_password');
-		$smtp_auth = $adb->query_result($mailserverresult,0,'smtp_auth');
-
-		$_REQUEST['server']=$mail_server;
-		$log->info("Mail Server Details => '".$mail_server."','".$mail_server_username."','".$mail_server_password."'");
-
-
-	$mail->Host = $mail_server;			// specify main and backup server
-	if($smtp_auth == 'true' || $smtp_auth == '1')
-		$mail->SMTPAuth = true;
-	else
-		$mail->SMTPAuth = false;
-	$mail->Username = $mail_server_username ;	// SMTP username
-	$mail->Password = $mail_server_password ;	// SMTP password
-	$mail->From = $from;
-	$mail->FromName = $initialfrom;
-	$log->info("Mail sending process : From Name & email id => '".$initialfrom."','".$from."'");
-	foreach($to as $pos=>$addr)
-	{
-		$mail->AddAddress($addr);                  // name is optional
-		$log->info("Mail sending process : To Email id = '".$addr."' (set in the mail object)");
-
-	}
-	$mail->WordWrap = 50;                                 // set word wrap to 50 characters
-
-	$mail->IsHTML(true);                                  // set email format to HTML
-
-	$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
-
 	$flag = MailSend($mail);
 	$log->info("After executing the mail->Send() function.");
+        
+        return $flag;
\ No newline at end of file
 }
 
 /**


More information about the vtigercrm-developers mailing list