private function sendEmailToDealersEmails($companyExProfiledto, $byMandrill = false)
 {
     $dealerEmailsText = $companyExProfiledto->getDealerEmails();
     $dealerEmailsArray = explode(';', $dealerEmailsText);
     $subject = $companyExProfiledto->getPriceEmailSubject();
     $body = stripslashes($companyExProfiledto->getPriceEmailBody());
     $fromEmail = $companyExProfiledto->getFromEmail();
     $companyName = $this->getCustomer()->getName();
     $isServiceCompany = $this->getUserLevel() == UserGroups::$SERVICE_COMPANY;
     $priceFiles = array();
     if ($isServiceCompany) {
         $companiesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyId = $companyExProfiledto->getServiceCompanyId();
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             foreach ($companyLastPrices as $key => $clp) {
                 $priceFiles[] = DATA_DIR . "/service_companies_prices/" . $companyId . '/' . $clp->getFileName() . '.' . $clp->getFileExt();
             }
         }
         $tmpSubdirectoryName = 'service_companies';
     } else {
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyId = $companyExProfiledto->getCompanyId();
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             foreach ($companyLastPrices as $key => $clp) {
                 $priceFiles[] = DATA_DIR . "/companies_prices/" . $companyId . '/' . $clp->getFileName() . '.' . $clp->getFileExt();
             }
         }
         $tmpSubdirectoryName = 'companies';
     }
     $allEmailFileAttachments = array();
     foreach ($priceFiles as $key => $priceFile) {
         $pfnParts = explode('.', $priceFile);
         $priceFileExtention = end($pfnParts);
         if (file_exists($priceFile)) {
             $postfix = "";
             if ($key > 0) {
                 $postfix = '_' . ($key + 1);
             }
             $allEmailFileAttachments[$companyName . ' Pricelist' . $postfix . '.' . $priceFileExtention] = $priceFile;
         }
     }
     $additionalAttachedFiles = array();
     $dir = HTDOCS_TMP_DIR_ATTACHMENTS . '/' . $tmpSubdirectoryName . '/' . $companyId . '/';
     if (is_dir($dir)) {
         $additionalAttachedFiles = scandir($dir);
     }
     foreach ($additionalAttachedFiles as $file) {
         $fileFullPath = $dir . $file;
         if (is_file($fileFullPath)) {
             $path_parts = pathinfo($fileFullPath);
             $basename = $path_parts['basename'];
             $fileDisplayName = substr($basename, strpos($basename, '_') + 1);
             $allEmailFileAttachments[$fileDisplayName] = $fileFullPath;
         }
     }
     if ($byMandrill == true) {
         $mandrillEmailSenderManager = new MandrillEmailSenderManager($this->getCmsVar("mandrill_api_key"));
         $body .= '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>';
         $body .= '<p style="font-size:10px"><a href="*|UNSUB:http://pcstore.am/unsub/' . ($isServiceCompany ? 'sc' : 's') . '/' . $companyId . '|*">Click here to unsubscribe.</a></p>';
         $res = $mandrillEmailSenderManager->sendHtmlEmail($dealerEmailsArray, $subject, $body, $fromEmail, $companyName, $allEmailFileAttachments, ($isServiceCompany ? 'service_company' : 'company') . '_' . $companyId);
         $sentSuccess = is_array($res);
     } else {
         $emailSenderManager = new EmailSenderManager('gmail');
         $res = $emailSenderManager->sendBulkEmailWithAttachmentsUsingPcstoreEmails($dealerEmailsArray, $subject, $body, array(), $allEmailFileAttachments, $fromEmail, $companyName);
         $sentSuccess = $res === true;
     }
     if ($sentSuccess !== true) {
         return $res;
     } else {
         $companyPriceEmailHistoryManager = CompanyPriceEmailHistoryManager::getInstance($this->config, $this->args);
         $companyPriceEmailHistoryManager->addRow($companyId, $isServiceCompany ? "service_company" : "company", $fromEmail, $dealerEmailsArray, $body, $subject, array_keys($allEmailFileAttachments));
     }
     return true;
 }