9namespace Bitrix\Sender\Integration\Sender\Mail;
11use Bitrix\Fileman\Block;
12use Bitrix\Main\Application;
13use Bitrix\Main\Config\Option;
15use Bitrix\Main\Loader;
16use Bitrix\Main\Localization\Loc;
18use Bitrix\Main\Result;
19use Bitrix\Main\SystemException;
20use Bitrix\Main\Web\DOM\Document;
21use Bitrix\Main\Web\DOM\StyleInliner;
22use Bitrix\Sender\Entity;
23use Bitrix\Sender\Integration;
24use Bitrix\Sender\Integration\Crm\Connectors\Helper;
25use Bitrix\Sender\Message;
26use Bitrix\Sender\Posting;
27use Bitrix\Sender\PostingRecipientTable;
28use Bitrix\Sender\Templates;
29use Bitrix\Sender\Transport;
30use Bitrix\Sender\Transport\TimeLimiter;
32Loc::loadMessages(__FILE__);
40 const CODE = self::CODE_MAIL;
65 return Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_NAME');
94 if ($this->configuration->hasOptions())
99 $this->configuration->setArrayOptions(
array(
103 'name' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_SUBJECT'),
106 'show_in_list' =>
true,
112 'id' =>
'#' . ($item[
'CODE'] ??
'') .
'#',
113 'text' => $item[
'NAME'] ??
'',
114 'title' => $item[
'DESC'] ??
'',
115 'items' => isset($item[
'ITEMS']) ? array_map(
119 'id' =>
'#' . ($item[
'CODE'] ??
'').
'#',
120 'text' => $item[
'NAME'] ??
'',
121 'title' => $item[
'DESC'] ??
''
128 Helper::getPersonalizeFieldsFromConnectors(),
136 'code' =>
'EMAIL_FROM',
137 'name' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_EMAIL_FROM'),
140 'show_in_list' =>
true,
141 'readonly_view' =>
function($value)
148 'type' =>
'mail-editor',
150 'name' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_MESSAGE'),
158 'code' =>
'PRIORITY',
159 'name' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_PRIORITY'),
163 'show_in_list' =>
true,
165 array(
'code' =>
'',
'value' =>
'(' . Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_NO') .
')'),
166 array(
'code' =>
'1 (Highest)',
'value' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_PRIORITY_HIGHEST')),
167 array(
'code' =>
'3 (Normal)',
'value' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_PRIORITY_NORMAL')),
168 array(
'code' =>
'5 (Lowest)',
'value' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_PRIORITY_LOWEST')),
170 'hint' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_PRIORITY_HINT'),
174 'code' =>
'LINK_PARAMS',
175 'name' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_LINK_PARAMS'),
179 'show_in_list' =>
true,
184 'code' =>
'ATTACHMENT',
185 'name' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_ATTACHMENT'),
193 'code' =>
'TRACK_MAIL',
194 'name' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_TRACK_MAIL'),
196 'show_in_list' =>
false,
198 'value' => Option::get(
'sender',
'track_mails')
202 'code' =>
'APPROVE_CONFIRMATION',
203 'name' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_APPROVE_CONFIRMATION'),
204 'hint' => Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_APPROVE_CONFIRMATION_HINT'),
206 'show_in_list' =>
false,
208 'value' => Option::get(
'sender',
'mail_consent'),
211 'code' =>
'APPROVE_CONFIRMATION_CONSENT',
213 'show_in_list' =>
false,
215 'show_preview' => true
219 TimeLimiter::prepareMessageConfiguration($this->configuration);
223 'type' =>
'template-type',
224 'code' =>
'TEMPLATE_TYPE',
225 'name' =>
'Template type',
229 'type' =>
'template-id',
230 'code' =>
'TEMPLATE_ID',
231 'name' =>
'Template id',
236 foreach ($list as $optionData)
238 $optionData = $optionData +
array(
257 Entity\Message::create()
259 ->loadConfiguration($id, $this->configuration);
264 $this->closureRefCountFix =
function () use (&
$instance)
269 $trackMail = $this->configuration->getOption(
'TRACK_MAIL')->getValue();
270 if (is_null($trackMail))
272 $this->configuration->getOption(
'TRACK_MAIL')->setValue(Option::get(
'sender',
'track_mails'));
275 $optionLinkParams = $this->configuration->getOption(
'LINK_PARAMS');
276 if ($optionLinkParams)
278 $optionLinkParams->setView(
279 function () use ($id, $optionLinkParams)
282 $GLOBALS[
'APPLICATION']->IncludeComponent(
283 'bitrix:sender.mail.link.editor',
'',
285 "INPUT_NAME" =>
"%INPUT_NAME%",
286 "VALUE" => $optionLinkParams->getValue(),
288 !$optionLinkParams->getValue()
292 !Application::getInstance()->getContext()->getRequest()->isPost()
294 "PLACEHOLDERS" =>
array(
296 "code" =>
"campaign",
297 "inputName" =>
"%INPUT_NAME_SUBJECT%"
300 "DEFAULT_VALUE" => Option::get(
303 'utm_source=newsletter&utm_medium=mail&utm_campaign=%campaign%'
307 return ob_get_clean();
312 $optionFrom = $this->configuration->getOption(
'EMAIL_FROM');
315 $optionFrom->setView(
316 function () use ($optionFrom)
319 $GLOBALS[
'APPLICATION']->IncludeComponent(
320 'bitrix:sender.mail.sender',
'',
322 "INPUT_NAME" =>
"%INPUT_NAME%",
323 "VALUE" => $optionFrom->getValue()
326 return ob_get_clean();
331 $this->configuration->set(
'BODY', $this->closureRefCountFix);
333 $mailHeaders =
array(
'Precedence' =>
'bulk');
335 $this->configuration->set(
'HEADERS', $mailHeaders);
336 TimeLimiter::prepareMessageConfigurationView($this->configuration);
363 $sizeInBytes = mb_strlen($mailBody);
364 $sizeInKilobytes = $sizeInBytes / 1024;
365 $limitInKilobytes = 2.4 * 1024;
366 $saveAsTemplate = $this->configuration->get(
'save_as_template') ===
'Y';
368 if ($saveAsTemplate && $sizeInKilobytes > $limitInKilobytes)
372 $result->addError(
new Error(Loc::getMessage(
'SENDER_INTEGRATION_MAIL_BODY_LIMIT')));
378 if ($mailBody && mb_strpos($mailBody,
'#UNSUBSCRIBE_LINK#') ===
false)
381 $result->addError(
new Error(Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_ERR_NO_UNSUB_LINK')));
386 &&
$configuration->getOption(
'APPROVE_CONFIRMATION')->getValue() ===
'Y'
387 && !
$configuration->getOption(
'APPROVE_CONFIRMATION_CONSENT')->getValue()
391 $result->addError(
new Error(Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_ERR_NO_APPROVE_CONFIRMATION_CONSENT')));
397 $this->configuration->getOption(
'LINK_PARAMS')->getValue(),
402 foreach ($utmTags as $utmTag => $value)
411 $emailFrom = $this->configuration->getOption(
'EMAIL_FROM')->getValue();
413 $this->configuration->getOption(
'EMAIL_FROM')->setValue($emailFrom);
415 $trackMail = $this->configuration->getOption(
'TRACK_MAIL')->getValue();
419 $this->configuration->getOption(
'TRACK_MAIL')->setValue(
'N');
421 return Entity\Message::create()
424 ->saveConfiguration($this->configuration);
435 return Entity\Message::create()
437 ->copyConfiguration($id);
447 static $isCloud =
null;
448 if ($isCloud ===
null)
451 Loader::includeModule(
'fileman');
469 Loader::includeModule(
'fileman');
471 $msg = $this->configuration->getOption(
'MESSAGE')->getValue();
482 $templateHtml =
null;
485 $templateHtml =
$template[
'FIELDS'][
'MESSAGE'][
'VALUE'];
487 if (!$templateHtml && isset(
$template[
'HTML']))
501 if(!
Block\
Content\Engine::create($document)->setContent($msg)->fill())
511 StyleInliner::inlineDocument($document);
512 $msg = $document->saveHTML();
522 if (Option::get(
'sender',
'use_inliner_for_each_template_mail',
'N') !=
'Y')
524 $this->configuration->set(
'BODY', $msg);
536 if (!$this->configuration->get(
'TEMPLATE_TYPE') || !$this->configuration->get(
'TEMPLATE_ID'))
542 ->withMessageCode(static::CODE)
543 ->withTypeId($this->configuration->get(
'TEMPLATE_TYPE'))
544 ->withId($this->configuration->get(
'TEMPLATE_ID'))
560 $optionHeaders = Option::get(
'sender',
'mail_headers',
'');
561 $optionHeaders = !empty($optionHeaders) ? unserialize($optionHeaders, [
'allowed_classes' =>
false]) :
array();
562 foreach ($optionHeaders as $optionHeader)
564 $optionHeader = trim($optionHeader);
570 $optionHeaderParts = explode(
':', $optionHeader);
571 $optionHeaderName = isset($optionHeaderParts[0]) ? $optionHeaderParts[0] :
'';
572 $optionHeaderName = trim($optionHeaderName);
573 $optionHeaderValue = isset($optionHeaderParts[1]) ? $optionHeaderParts[1] :
'';
574 $optionHeaderValue = trim($optionHeaderValue);
575 if (!$optionHeaderName || !$optionHeaderValue)
580 $headerList[$optionHeaderName] = $optionHeaderValue;
584 foreach (
$headerList as $optionHeaderName => $optionHeaderValue)
586 $headers[$optionHeaderName] = $optionHeaderValue;
static replaceCharset($html, $charset='#CHARSET#', $add=false)
static removePhpFromHtml($html, $previousHtml=null, $canEditPhp=false, $canUseLpa=false)
static fillHeadersByOptionHeaders(array $headers=array())
setConfigurationOptions()
loadConfiguration($id=null)
saveConfiguration(Message\Configuration $configuration)
const TYPE_CONSENT_CONTENT
static getPersonalizeList()
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(! $readOnly &&$adminList->EditAction()) if(! $readOnly &&($listID=$adminList->GroupAction()) $headerList)
$GLOBALS['____1690880296']