Example #1
0
 /**
  * Returns a Connector to either MailBox or Internal Drafts
  * @param String $folder - Name of the folder
  * @return MailManager_Connector
  */
 protected function getConnector($folder = '')
 {
     if (!$this->mConnector || $this->mFolder != $folder) {
         if ($folder == "__vt_drafts") {
             $draftController = new MailManager_Draft_View();
             $this->mConnector = $draftController->connectorWithModel();
         } else {
             if ($this->mConnector) {
                 $this->mConnector->close();
             }
             $model = $this->getMailboxModel();
             $this->mConnector = MailManager_Connector_Connector::connectorWithModel($model, $folder);
         }
         $this->mFolder = $folder;
     }
     return $this->mConnector;
 }
Example #2
0
 /**
  * Function sends mail
  */
 public function send()
 {
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $rootDirectory = vglobal('root_directory');
     $mailer = Emails_Mailer_Model::getInstance();
     $mailer->IsHTML(true);
     $fromEmail = $this->getFromEmailAddress();
     $replyTo = $currentUserModel->get('email1');
     $userName = $currentUserModel->getName();
     // To eliminate the empty value of an array
     $toEmailInfo = array_filter($this->get('toemailinfo'));
     $toMailNamesList = array_filter($this->get('toMailNamesList'));
     foreach ($toMailNamesList as $id => $emailData) {
         foreach ($emailData as $key => $email) {
             if ($toEmailInfo[$id]) {
                 array_push($toEmailInfo[$id], $email['value']);
             }
         }
     }
     $emailsInfo = array();
     foreach ($toEmailInfo as $id => $emails) {
         foreach ($emails as $key => $value) {
             array_push($emailsInfo, $value);
         }
     }
     $toFieldData = array_diff(explode(',', $this->get('saved_toid')), $emailsInfo);
     $toEmailsData = array();
     $i = 1;
     foreach ($toFieldData as $value) {
         $toEmailInfo['to' . $i++] = array($value);
     }
     $attachments = $this->getAttachmentDetails();
     $status = false;
     // Merge Users module merge tags based on current user.
     $mergedDescription = getMergedDescription($this->get('description'), $currentUserModel->getId(), 'Users');
     $mergedSubject = getMergedDescription($this->get('subject'), $currentUserModel->getId(), 'Users');
     foreach ($toEmailInfo as $id => $emails) {
         $mailer->reinitialize();
         $mailer->ConfigSenderInfo($fromEmail, $userName, $replyTo);
         $old_mod_strings = vglobal('mod_strings');
         $description = $this->get('description');
         $subject = $this->get('subject');
         $parentModule = $this->getEntityType($id);
         if ($parentModule) {
             $currentLanguage = Vtiger_Language_Handler::getLanguage();
             $moduleLanguageStrings = Vtiger_Language_Handler::getModuleStringsFromFile($currentLanguage, $parentModule);
             vglobal('mod_strings', $moduleLanguageStrings['languageStrings']);
             if ($parentModule != 'Users') {
                 // Apply merge for non-Users module merge tags.
                 $description = getMergedDescription($mergedDescription, $id, $parentModule);
                 $subject = getMergedDescription($mergedSubject, $id, $parentModule);
             } else {
                 // Re-merge the description for user tags based on actual user.
                 $description = getMergedDescription($description, $id, 'Users');
                 $subject = getMergedDescription($mergedSubject, $id, 'Users');
                 vglobal('mod_strings', $old_mod_strings);
             }
         }
         if (strpos($description, '$logo$')) {
             $description = str_replace('$logo$', "<img src='cid:logo' />", $description);
             $logo = true;
         }
         foreach ($emails as $email) {
             $mailer->Body = '';
             if ($parentModule) {
                 $mailer->Body = $this->getTrackImageDetails($id, $this->isEmailTrackEnabled());
             }
             $mailer->Body .= $description;
             $mailer->Signature = str_replace(array('\\r\\n', '\\n'), '<br>', $currentUserModel->get('signature'));
             if ($mailer->Signature != '') {
                 $mailer->Body .= '<br><br>' . decode_html($mailer->Signature);
             }
             $mailer->Subject = $subject;
             $mailer->AddAddress($email);
             //Adding attachments to mail
             if (is_array($attachments)) {
                 foreach ($attachments as $attachment) {
                     $fileNameWithPath = $rootDirectory . $attachment['path'] . $attachment['fileid'] . "_" . $attachment['attachment'];
                     if (is_file($fileNameWithPath)) {
                         $mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
                     }
                 }
             }
             if ($logo) {
                 //While sending email template and which has '$logo$' then it should replace with company logo
                 $mailer->AddEmbeddedImage(dirname(__FILE__) . '/../../../layouts/vlayout/skins/images/logo_mail.jpg', 'logo', 'logo.jpg', 'base64', 'image/jpg');
             }
             $ccs = array_filter(explode(',', $this->get('ccmail')));
             $bccs = array_filter(explode(',', $this->get('bccmail')));
             if (!empty($ccs)) {
                 // SalesPlatform.ru begin
                 foreach ($ccs as $cc) {
                     $mailer->AddCC($idn->encode($cc));
                 }
                 //$mailer->AddCC($cc);
                 // SalesPlatform.ru end
             }
             if (!empty($bccs)) {
                 // SalesPlatform.ru begin
                 foreach ($bccs as $bcc) {
                     $mailer->AddBCC($idn->encode($bcc));
                 }
                 //$mailer->AddBCC($bcc);
                 // SalesPlatform.ru end
             }
         }
         // SalesPlatform.ru begin
         $idn = new idna_convert();
         $query = "select * from vtiger_systems where server_type=?";
         $params = array('email');
         //SalesPlatform begin fix bug
         $adb = PearDatabase::getInstance();
         //SalesPaltform.ru end
         $result = $adb->pquery($query, $params);
         $server_username = $adb->query_result($result, 0, 'server_username');
         $from_name_db = $adb->query_result($result, 0, 'from_name');
         $server_port = $adb->query_result($result, 0, 'server_port');
         $server_tls = $adb->query_result($result, 0, 'server_tls');
         if ($server_username != '') {
             $server_username = $idn->encode($server_username);
             $mailer->Username = $server_username;
         }
         if (isset($from_name_db) && $from_name_db != '') {
             $mailer->FromName = decode_html($from_name_db);
         }
         $from_email = $adb->query_result($result, 0, 'from_email_field');
         if ($from_email != '') {
             $mailer->From = $idn->encode($from_email);
         }
         if (!empty($server_port) && $server_port != 0) {
             $mailer->Port = $server_port;
         }
         if (!empty($server_tls) && $server_tls != 'no') {
             $mailer->SMTPSecure = $server_tls;
         }
         $use_sendmail = $adb->query_result($result, 0, 'use_sendmail');
         if ($use_sendmail == "on") {
             $mailer->IsSendmail();
         } else {
             $mailer->IsSMTP();
         }
         // SalesPlatform.ru end
         $status = $mailer->Send(true);
         if (!$status) {
             $status = $mailer->getError();
         } else {
             $mailString = $mailer->getMailString();
             $mailBoxModel = MailManager_Mailbox_Model::activeInstance();
             $folderName = $mailBoxModel->folder();
             if (!empty($folderName) && !empty($mailString)) {
                 $connector = MailManager_Connector_Connector::connectorWithModel($mailBoxModel, '');
                 imap_append($connector->mBox, $connector->mBoxUrl . $folderName, $mailString, "\\Seen");
             }
         }
     }
     return $status;
 }
Example #3
0
 /**
  * Function sends mail
  */
 public function send()
 {
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $rootDirectory = vglobal('root_directory');
     $mailer = Emails_Mailer_Model::getInstance();
     $mailer->IsHTML(true);
     $fromEmail = $this->getFromEmailAddress();
     $replyTo = $currentUserModel->get('email1');
     $userName = $currentUserModel->getName();
     // To eliminate the empty value of an array
     $toEmailInfo = array_filter($this->get('toemailinfo'));
     $toMailNamesList = array_filter($this->get('toMailNamesList'));
     foreach ($toMailNamesList as $id => $emailData) {
         foreach ($emailData as $key => $email) {
             if ($toEmailInfo[$id]) {
                 array_push($toEmailInfo[$id], $email['value']);
             }
         }
     }
     $emailsInfo = array();
     foreach ($toEmailInfo as $id => $emails) {
         foreach ($emails as $key => $value) {
             array_push($emailsInfo, $value);
         }
     }
     $toFieldData = array_diff(explode(',', $this->get('saved_toid')), $emailsInfo);
     $toEmailsData = array();
     $i = 1;
     foreach ($toFieldData as $value) {
         $toEmailInfo['to' . $i++] = array($value);
     }
     $attachments = $this->getAttachmentDetails();
     $status = false;
     // Merge Users module merge tags based on current user.
     $mergedDescription = getMergedDescription($this->get('description'), $currentUserModel->getId(), 'Users');
     foreach ($toEmailInfo as $id => $emails) {
         $mailer->reinitialize();
         $mailer->ConfigSenderInfo($fromEmail, $userName, $replyTo);
         $old_mod_strings = vglobal('mod_strings');
         $description = $this->get('description');
         $parentModule = $this->getEntityType($id);
         if ($parentModule) {
             $currentLanguage = Vtiger_Language_Handler::getLanguage();
             $moduleLanguageStrings = Vtiger_Language_Handler::getModuleStringsFromFile($currentLanguage, $parentModule);
             vglobal('mod_strings', $moduleLanguageStrings['languageStrings']);
             if ($parentModule != 'Users') {
                 // Apply merge for non-Users module merge tags.
                 $description = getMergedDescription($mergedDescription, $id, $parentModule);
             } else {
                 // Re-merge the description for user tags based on actual user.
                 $description = getMergedDescription($description, $id, 'Users');
                 vglobal('mod_strings', $old_mod_strings);
             }
         }
         if (strpos($description, '$logo$')) {
             $description = str_replace('$logo$', "<img src='cid:logo' />", $description);
             $logo = true;
         }
         foreach ($emails as $email) {
             $mailer->Body = $description;
             $mailer->Signature = str_replace(array('\\r\\n', '\\n'), '<br>', $currentUserModel->get('signature'));
             if ($mailer->Signature != '') {
                 $mailer->Body .= '<br><br>' . decode_html($mailer->Signature);
             }
             $mailer->Subject = $this->get('subject');
             $mailer->AddAddress($email);
             //Adding attachments to mail
             if (is_array($attachments)) {
                 foreach ($attachments as $attachment) {
                     $fileNameWithPath = $rootDirectory . $attachment['path'] . $attachment['fileid'] . "_" . $attachment['attachment'];
                     if (is_file($fileNameWithPath)) {
                         $mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
                     }
                 }
             }
             if ($logo) {
                 //While sending email template and which has '$logo$' then it should replace with company logo
                 $company = Settings_Vtiger_CompanyDetails_Model::getInstance();
                 $logo = $company->getLogoPath('logoname');
                 $mailer->AddEmbeddedImage(dirname(__FILE__) . '/../../../' . $logo, 'logo', 'logo.jpg', 'base64', 'image/jpg');
             }
             $ccs = array_filter(explode(',', $this->get('ccmail')));
             $bccs = array_filter(explode(',', $this->get('bccmail')));
             if (!empty($ccs)) {
                 foreach ($ccs as $cc) {
                     $mailer->AddCC($cc);
                 }
             }
             if (!empty($bccs)) {
                 foreach ($bccs as $bcc) {
                     $mailer->AddBCC($bcc);
                 }
             }
         }
         $status = $mailer->Send(true);
         if (!$status) {
             $status = $mailer->getError();
         } else {
             $mailString = $mailer->getMailString();
             $mailBoxModel = MailManager_Mailbox_Model::activeInstance();
             $folderName = $mailBoxModel->folder();
             if (!empty($folderName) && !empty($mailString)) {
                 $connector = MailManager_Connector_Connector::connectorWithModel($mailBoxModel, '');
                 imap_append($connector->mBox, $connector->mBoxUrl . $folderName, $mailString, "\\Seen");
             }
         }
     }
     return $status;
 }