126 public static function click($recipientId, $url)
128 $postingContactPrimary = [
'ID' => $recipientId];
129 $row = PostingRecipientTable::getRowById($postingContactPrimary);
137 $read = PostingReadTable::getRowById(
139 'POSTING_ID' => $row[
'POSTING_ID'],
140 'RECIPIENT_ID' => $row[
'ID']
145 static::read($recipientId);
148 $postingDb = PostingTable::getList(
151 'filter' => [
'=ID' => $row[
'POSTING_ID']],
154 if ($postingDb->fetch())
156 $deleteParameters = [
'bx_sender_conversion_id'];
157 $letter = Entity\Letter::createInstanceByPostingId($row[
'POSTING_ID']);
158 $linkParams = $letter->getMessage()
160 ->get(
'LINK_PARAMS');
164 parse_str($linkParams, $parametersTmp);
165 if (is_array($parametersTmp))
167 $parametersTmp = array_keys($parametersTmp);
168 $deleteParameters = array_merge($deleteParameters, $parametersTmp);
172 $uri = new \Bitrix\Main\Web\Uri($url);
173 $fixedUrl = $uri->deleteParams($deleteParameters,
false)
176 $fixedUrl = urldecode($fixedUrl);
178 if(mb_strpos($fixedUrl,
'pub/mail/unsubscribe.php') ===
false)
180 $addClickDb = PostingClickTable::add(
182 'POSTING_ID' => $row[
'POSTING_ID'],
183 'RECIPIENT_ID' => $row[
'ID'],
189 if ($addClickDb && $addClickDb->isSuccess())
194 'URL_FIXED' => $fixedUrl,
195 'CLICK_ID' => $addClickDb->getId(),
198 $event =
new Event(
'sender',
'OnAfterRecipientClick', [$eventData]);
204 if ($row[
'CONTACT_ID'])
206 ContactTable::update(
256 $recipientEmail = $address;
257 $emailParts = explode(
'@', $recipientEmail);
258 $recipientName = $emailParts[0];
262 $mailingChain = MailingChainTable::getRowById([
'ID' => $mailingChainId]);
264 'NAME' => $recipientName,
265 'EMAIL_TO' => $address,
266 'USER_ID' => $USER->GetID(),
267 'SENDER_CHAIN_ID' => $mailingChain[
"ID"],
268 'SENDER_CHAIN_CODE' =>
'sender_chain_item_'.$mailingChain[
"ID"]
272 $message = $letter->getMessage();
276 $message->getReadTracker()
277 ->setModuleId(
'sender')
278 ->setFields([
'RECIPIENT_ID' => 0])
279 ->setSiteId($siteId);
281 $message->getClickTracker()
282 ->setModuleId(
'sender')
283 ->setFields([
'RECIPIENT_ID' => 0])
284 ->setUriParameters([
'bx_sender_conversion_id' => 0])
285 ->setSiteId($siteId);
287 $message->getUnsubTracker()
288 ->setModuleId(
'sender')
291 'MAILING_ID' => !empty($mailingChain) ? $mailingChain[
'MAILING_ID'] : 0,
296 ->setSiteId($siteId);
298 $message->getUnsubTracker()
299 ->setHandlerUri(Option::get(
'sender',
'unsub_link'));
301 $message->setFields($fields);
302 $result = $message->send();
304 return $result ? static::SEND_RESULT_SENT : static::SEND_RESULT_ERROR;
318 public static function send($id, $timeout = 0, $maxMailCount = 0)
320 $letter = Entity\Letter::createInstanceByPostingId($id);
323 $sender->setThreadStrategy(
324 MessageMarketingFb::checkSelf($sender->getMessage()->getCode()) ?
325 ThreadStrategyContext::buildStrategy(
326 IThreadStrategy::SINGLE
327 ): Runtime\Env::getThreadContext()
329 ->setLimit($maxMailCount)
330 ->setTimeout($timeout)
333 static::$threadId = $sender->getThreadStrategy()->getThreadId();
335 switch ($sender->getResultCode())
337 case Posting\Sender::RESULT_CONTINUE:
338 $result = static::SEND_RESULT_CONTINUE;
340 case Posting\Sender::RESULT_ERROR:
341 $result = static::SEND_RESULT_ERROR;
343 case Posting\Sender::RESULT_WAITING_RECIPIENT:
344 $result = static::SEND_RESULT_WAITING_RECIPIENT;
346 case Posting\Sender::RESULT_WAIT:
347 $result = static::SEND_RESULT_WAIT;
349 case Posting\Sender::RESULT_SENT:
351 $result = static::SEND_RESULT_SENT;
355 $limiter = $sender->getExceededLimiter();
356 if ($result === static::SEND_RESULT_CONTINUE && $limiter)
360 if ($limiter->getParameter(
'sendingStart'))
362 $currentTime = $limiter->getParameter(
'currentTime');
363 $sendingStart = $limiter->getParameter(
'sendingStart');
364 $sendingStartDate = (new \DateTime())->setTimestamp($sendingStart);
366 $sendingStartDate = $currentTime > $sendingStart
367 ? $sendingStartDate->add(\DateInterval::createFromDateString(
'1 day'))
370 $date = Type\DateTime::createFromPhp($sendingStartDate);
372 elseif ($limiter->getUnit())
380 $date->add(
'2 minute');
383 $letter->getState()->updatePlannedDateSend($date);