270 public function send(array $codes, array $parameters)
275 $result->addError(
new Error(
"Testing not supported."));
280 if(!Security\User::current()->isAgreementAccepted())
286 $campaignId = isset($parameters[
'CAMPAIGN_ID']) ? $parameters[
'CAMPAIGN_ID'] : Entity\Campaign::getDefaultId(SITE_ID);
287 $name = isset($parameters[
'NAME']) ? $parameters[
'NAME'] :
null;
288 $name = $name ?:
$GLOBALS[
'USER']->getFirstName();
289 $userId = isset($parameters[
'USER_ID']) ? $parameters[
'USER_ID'] :
null;
290 $userId = $userId ?:
$GLOBALS[
'USER']->getID();
291 $fields = isset($parameters[
'FIELDS']) ? $parameters[
'FIELDS'] : array();
293 $this->message->getTransport()->start();
296 foreach ($codes as $code)
298 if (self::MAX_SEND_CODES && $count++ >= self::MAX_SEND_CODES)
300 $result->addError(
new Error(
Loc::getMessage(
'SENDER_MESSAGE_TESTER_ERROR_MAX_COUNT', [
'%count%' => self::MAX_SEND_CODES])));
304 if ($this->message->getTransport()->isLimitsExceeded($this->message))
306 $limiter = $this->message->getTransport()->getExceededLimiter();
309 if (($limiter instanceof
CountLimiter) && $limiter->getName() ===
'portal_verify')
311 $result->addError(
new Error(
Loc::getMessage(
'SENDER_MESSAGE_TESTER_ERROR_LIMIT_PORTAL_VERIFY_FAILED', array(
'%name%' => $code))));
317 $result->addError(
new Error(
Loc::getMessage(
'SENDER_MESSAGE_TESTER_ERROR_LIMIT_EXCEEDED', array(
'%name%' => $code))));
322 if (Integration\Bitrix24\Service::isCloud())
324 if ($this->message->getCode() ===
Message\IBase::CODE_MAIL) {
325 $verifyLimit = Integration\Bitrix24\Limitation\PortalVerifyLimit::instance();
326 if ($verifyLimit->getCurrent() >= $verifyLimit->getLimit())
328 $result->addError(
new Error(
Loc::getMessage(
'SENDER_MESSAGE_TESTER_ERROR_LIMIT_PORTAL_VERIFY_FAILED', array(
'%name%' => $code))));
333 $testerDailyLimit = Integration\Bitrix24\Limitation\TesterDailyLimit::instance();
334 if ($testerDailyLimit->getCurrent() >= $testerDailyLimit->getLimit())
336 $result->addError(
new Error(
Loc::getMessage(
'SENDER_MESSAGE_TESTER_ERROR_LIMIT_EXCEEDED', array(
'%name%' => $code))));
341 $type = Recipient\Type::detect($code);
344 $code = Recipient\Normalizer::normalize($code, $type);
346 if (!$type || !$code)
348 $result->addError(
new Error(
Loc::getMessage(
'SENDER_MESSAGE_TESTER_ERROR_WRONG_RECIPIENT', array(
'%name%' => $code))));
354 'CAMPAIGN_ID' => $campaignId,
355 'CONTACT_CODE' => $code,
356 'CONTACT_TYPE' => $type,
358 'USER_ID' => $userId,
362 Posting\Sender::applyRecipientToMessage($this->message, $recipient,
true);
365 $sendResult = $this->message->send();
366 if (!$sendResult && $result->isSuccess())
368 $to = $this->message->getRecipientCode();
369 $result->addError(
new Error(
Loc::getMessage(
'SENDER_MESSAGE_TESTER_ERROR_SENT', array(
'%name%' => $to))));
377 Integration\Bitrix24\Limitation\DailyLimit::increment();
378 Integration\Bitrix24\Limitation\TesterDailyLimit::increment();
384 $result->addError(
new Error($e->getMessage()));
388 $this->message->getTransport()->end();