/** * @param integer $priority * @param array $recipients * @param string $subject * @param Logic_WebService_Mail_Content $content * @param mixed $attachments * @param string $charCode * @param boolean $isHtml * @throws Logic_WebService_Exception * @return Logic_WebService_Mail_Response */ public function handler($priority, array $recipients, $subject, $content, Logic_WebService_Mail_Attachment $attachments, $charCode = 'UTF-8', $isHtml = false) { $timeLimit = 30; // zabezpieczenie przed przekroczeniem limitu czasu wykonywania skryptu $modelCounter = new MailCounter(); $modelPackageStorage = new MailPackageStorage(); $modelStorage = new MailStorage(); $content = new Logic_WebService_Mail_Content($content); $limit = new Logic_WebService_Element_Limit($this->_client, $this->_service); $response = new Logic_WebService_Mail_Response(); $response->setStatus(true); $toReport = array(); $numAdded = 0; $numRejected = 0; if (empty($recipients)) { throw new Logic_WebService_Mail_Exception('Nie podano adresow e-mail do rozsylki', 450); } $modelPackage = new MailPackage(); $packageId = $modelPackage->addPackage(array('ws_client_id' => $this->_client->getParams()->id, 'ws_service_id' => $this->_service->getParams()->id, 'is_active' => 'true', 'mailer_priority' => $priority, 'package_comment' => null)); if (is_object($attachments) && $attachments->areAttachments()) { $model = new MailAttachment(); $model->addAttachment($packageId, $attachments->mapToModel()); } $isSomethindToSend = false; foreach ($recipients as $mail => $individualContent) { set_time_limit($timeLimit + 30); try { $recipient = new Logic_WebService_Mail_Recipient($mail); if (!$this->_environment->checkStatus()) { $recipient->checkEmailOnWhiteList(); } if ($recipient->checkEmailOnBlackList($this->_client->getParams()->id, $recipent)) { $mailBlacklistModel = new MailBlacklistStorage(); $mailBlacklistModel->addMail($this->_client->getParams()->id, $this->_service->getParams()->id, $recipient, $subject, $content, $packageId); continue; } $limit->check($modelCounter, $recipient->getRecipient()->id); $mailContent = $individualContent ? new Logic_WebService_Mail_Content($individualContent) : $content; $limit->checkByContent($modelCounter, $recipient->getRecipient()->id, $mailContent); $isSomethindToSend = true; // jednak ktorys e-mail przeszedl weryfikacje $numAdded++; $modelPackageStorage->addPackage(array('mail_package_id' => $packageId, 'mail_address' => $mail, 'mail_subject' => $subject, 'mail_content' => $mailContent->getContent(), 'mail_content_charcode' => $charCode, 'mail_content_is_html' => $isHtml)); $modelStorage->addMail($this->_client->getParams()->id, $this->_service->getParams()->id, $recipient, $subject, $mailContent, $response, $packageId); } catch (Logic_WebService_Exception $e) { $numRejected++; $toReport[] = array('address' => $mail, 'content' => $individualContent, 'reason' => $e->getMessage()); } catch (Exception $e) { throw new Logic_WebService_Exception($e->getMessage()); } } if ($isSomethindToSend) { // przygodowano pakiet danych do rozsylki $response->setMailId($packageId)->setStatus(true)->setMessage('Dodano do kolejki')->setAdded($numAdded)->setRejected($numRejected)->setReport($toReport); } else { // wszystkie adresy odpadly $response->setStatus(false)->setMessage('Brak adresow do rozsylki')->setAdded($numAdded)->setRejected($numRejected)->setReport($toReport); } return $response; }
/** * @param Logic_WebService_Mail_Recipient $recipient * @param string $subject * @param Logic_WebService_Mail_Content $content * @param string $charCode * @param boolean $isHtml * @throws Logic_WebService_Mail_Exception * @return Logic_WebService_Mail_Response */ public function handle($recipient, array $recipientCC, array $recipientBCC, $subject, $content, Logic_WebService_Mail_Attachment $attachments, $charCode = 'UTF-8', $isHtml = false, $replyto = null) { $recipient = new Logic_WebService_Mail_Recipient($recipient); $recipientCCChecker = new Logic_WebService_Mail_RecipientCC(); $recipientCCChecker->checkAddresses($recipientCC); $recipientCCChecker->checkAddresses($recipientBCC); $mailBlacklistModel = new MailBlacklistStorage(); if ($recipient->checkEmailOnBlackList($this->_client->getParams()->id)) { $mailBlacklistModel->addMail($this->_client->getParams()->id, $this->_service->getParams()->id, $recipient, $subject, $content, 0, $recipientCC, $recipientBCC); throw new Logic_WebService_Mail_Exception('Proba wyslania e-maila testowego na adres e-mail obecny na blacklist: ' . $this->_mail, 417); } foreach ($recipientCC as $recCC) { if ($recCC && $recipient->checkEmailOnBlackList($this->_client->getParams()->id, $recCC)) { $mailBlacklistModel->addMail($this->_client->getParams()->id, $this->_service->getParams()->id, $recipient, $subject, $content, 0, $recipientCC, $recipientBCC); throw new Logic_WebService_Mail_Exception('Proba wyslania e-maila testowego na adres e-mail (CC) obecny na blacklist: ' . $this->_mail, 417); } } foreach ($recipientBCC as $recBCC) { if ($recBCC && $recipient->checkEmailOnBlackList($this->_client->getParams()->id, $recBCC)) { $mailBlacklistModel->addMail($this->_client->getParams()->id, $this->_service->getParams()->id, $recipient, $subject, $content, 0, $recipientCC, $recipientBCC); throw new Logic_WebService_Mail_Exception('Proba wyslania e-maila testowego na adres e-mail (BCC) obecny na blacklist: ' . $this->_mail, 417); } } if (!$this->_environment->checkStatus()) { $recipient->checkEmailOnWhiteList(); $recipientCCChecker->checkEmailOnWhiteList($recipientCC); $recipientCCChecker->checkEmailOnWhiteList($recipientBCC); } $modelCounter = new MailCounter(); $limit = new Logic_WebService_Element_Limit($this->_client, $this->_service); $limit->check($modelCounter, $recipient->getRecipient()->id); $limit->checkByContent($modelCounter, $recipient->getRecipient()->id, $content); if (!$subject) { throw new Logic_WebService_Mail_Exception('Nie podano tytulu wiadomosci e-mail', 425); } $params = $this->_service->getParams(); if ($content->countContentLenght() <= 0) { throw new Logic_WebService_Sms_Exception('Proba wyslania pustego maila (brak tresci przygotowanej do wysylki)', 510); } $mail = new Logic_WebService_Mail_Transport_ZendMail(); $result = $mail->handle($params->from_title, $params->from_mail, $recipient->getMail(), $recipientCC, $recipientBCC, $subject, $content->getContent(), $attachments, $params->smtp_host, $params->smtp_port, $params->smtp_login, $params->smtp_password, $charCode, $isHtml, $replyto); $response = new Logic_WebService_Mail_Response(); if ($result) { $response->setStatus(true)->setMessage('Wysłano e-mail'); } else { $response->setStatus(false)->setMessage('Blad aplikacji'); } $model = new MailStorage(); $response->setMailId($model->addMail($this->_client->getParams()->id, $this->_service->getParams()->id, $recipient, $subject, $content, $response)); return $response; }
private function sendMail($service_id, $email, $subject, $content, $cc = array(), $bcc = array()) { $this->_service = new Logic_WebService_Element_Service(); $this->_service->getService($service_id); $recipient = new Logic_WebService_Mail_Recipient($email); $content = new Logic_WebService_Mail_Content($content); if (!$subject) { throw new Logic_WebService_Mail_Exception('Nie podano tytulu wiadomosci e-mail', 425); } $params = $this->_service->getParams(); if ($content->countContentLenght() <= 0) { throw new Logic_WebService_Sms_Exception('Proba wyslania pustego maila (brak tresci przygotowanej do wysylki)', 510); } if ($cc === array('')) { $cc = array(); } if ($bcc === array('')) { $bcc = array(); } if (!is_array($cc)) { $cc = array(); } if (!is_array($bcc)) { $bcc = array(); } $mail = new Logic_WebService_Mail_Transport_ZendMail(); $result = $mail->handle($params->from_title, $params->from_mail, $recipient->getMail(), $cc, $bcc, $subject, $content->getContent(), $attachments, $params->smtp_host, $params->smtp_port, $params->smtp_login, $params->smtp_password, $charCode, $isHtml); $response = new Logic_WebService_Mail_Response(); if ($result) { $response->setStatus(true)->setMessage('Wysłano e-mail'); } else { $response->setStatus(false)->setMessage('Blad aplikacji'); } return $response; }