• Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/posting/sender.php
  • Класс: BitrixSenderPostingSender
  • Вызов: Sender::sendToRecipients
private function sendToRecipients($recipients)
{
	$sendResult = null;
	$dataToInsert = [];
	try
	{
		foreach ($recipients as $recipient)
		{
			if ($this->isPrevented() || $this->isStoppedOnRun())
			{
				break;
			}

			$this->setPostingDateSend();
			$eventData = [];
			if ($this->canDenySendToRecipient($recipient))
			{
				$this->updateRecipientStatus($recipient['ID'],PostingRecipientTable::SEND_RESULT_ERROR);
				$sendResult = false;
				$eventData = $this->executeEvent($recipient, $sendResult);
			}
			elseif($this->canSendMessageToRecipient($recipient))
			{
				$sendResult = $this->sendToRecipient($recipient);
				if ($this->isPrevented())
				{
					break;
				}
				$sendResultStatus = ($sendResult ?
					PostingRecipientTable::SEND_RESULT_SUCCESS :
					PostingRecipientTable::SEND_RESULT_ERROR
				);
				$this->updateRecipientStatus($recipient['ID'],$sendResultStatus);
				$eventData = $this->executeEvent($recipient, $sendResult);
			}
			elseif ($this->canSendConsentToRecipient($recipient))
			{
				$sendResult = $this->executeConsentToRecipient($recipient);
				$sendResultStatus = (
					$sendResult ?
					PostingRecipientTable::SEND_RESULT_WAIT_ACCEPT :
					PostingRecipientTable::SEND_RESULT_ERROR
				);
				$this->updateRecipientStatus($recipient['ID'],$sendResultStatus);
			}

			$dataToInsert[] = $eventData;

			if (Bitrix24Service::isCloud() && $eventData['SEND_RESULT'] && $this->letter->getMessage()->getCode() === MessageiBase::CODE_MAIL)
			{
				Bitrix24LimitationDailyLimit::increment();
			}
			// limit executing script by time
			if ($this->isTimeout() || $this->isLimitExceeded() || $this->isTransportLimitsExceeded())
			{
				break;
			}
			// increment sending statistic
			$this->sentCount++;
		}
	} catch(Exception $e)
	{}

	try
	{
		if($dataToInsert)
		{
			IntegrationEventHandler::onAfterPostingSendRecipientMultiple(
				$dataToInsert,
				$this->letter
			);
		}
	} catch(Exception $e)
	{

	}

	return $sendResult;
}