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'),
161 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
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'),
177 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
179 'show_in_list' =>
true,
184 'code' =>
'ATTACHMENT',
185 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_ATTACHMENT'),
188 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
193 'code' =>
'TRACK_MAIL',
194 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_TRACK_MAIL'),
195 'hint' =>
Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_TRACK_MAIL_HINT'),
196 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
197 'show_in_list' =>
false,
199 'value' => Option::get(
'sender',
'track_mails')
202 'type' => Message\ConfigurationOption::TYPE_CONSENT,
203 'code' =>
'APPROVE_CONFIRMATION',
204 'name' =>
Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_APPROVE_CONFIRMATION'),
205 'hint' =>
Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_CONFIG_APPROVE_CONFIRMATION_HINT'),
206 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
207 'show_in_list' =>
false,
209 'value' => Option::get(
'sender',
'mail_consent'),
211 'type' => Message\ConfigurationOption::TYPE_CONSENT_CONTENT,
212 'code' =>
'APPROVE_CONFIRMATION_CONSENT',
213 'group' => Message\ConfigurationOption::GROUP_ADDITIONAL,
214 'show_in_list' =>
false,
216 'show_preview' => true
220 TimeLimiter::prepareMessageConfiguration($this->configuration);
224 'type' =>
'template-type',
225 'code' =>
'TEMPLATE_TYPE',
226 'name' =>
'Template type',
230 'type' =>
'template-id',
231 'code' =>
'TEMPLATE_ID',
232 'name' =>
'Template id',
237 foreach ($list as $optionData)
239 $optionData = $optionData + array(
258 Entity\Message::create()
260 ->loadConfiguration($id, $this->configuration);
265 $this->closureRefCountFix =
function () use (&$instance)
267 return $instance->getMailBody();
270 $trackMail = $this->configuration->getOption(
'TRACK_MAIL')->getValue();
271 if (is_null($trackMail))
273 $this->configuration->getOption(
'TRACK_MAIL')->setValue(Option::get(
'sender',
'track_mails'));
276 $optionLinkParams = $this->configuration->getOption(
'LINK_PARAMS');
277 if ($optionLinkParams)
279 $optionLinkParams->setView(
280 function () use ($id, $optionLinkParams)
283 $GLOBALS[
'APPLICATION']->IncludeComponent(
284 'bitrix:sender.mail.link.editor',
'',
286 "INPUT_NAME" =>
"%INPUT_NAME%",
287 "VALUE" => $optionLinkParams->getValue(),
289 !$optionLinkParams->getValue()
295 "PLACEHOLDERS" => array(
297 "code" =>
"campaign",
298 "inputName" =>
"%INPUT_NAME_SUBJECT%"
301 "DEFAULT_VALUE" => Option::get(
304 'utm_source=newsletter&utm_medium=mail&utm_campaign=%campaign%'
308 return ob_get_clean();
313 $optionFrom = $this->configuration->getOption(
'EMAIL_FROM');
316 $optionFrom->setView(
317 function () use ($optionFrom)
320 $GLOBALS[
'APPLICATION']->IncludeComponent(
321 'bitrix:sender.mail.sender',
'',
323 "INPUT_NAME" =>
"%INPUT_NAME%",
324 "VALUE" => $optionFrom->getValue()
327 return ob_get_clean();
332 $this->configuration->set(
'BODY', $this->closureRefCountFix);
334 $mailHeaders = array(
'Precedence' =>
'bulk');
336 $this->configuration->set(
'HEADERS', $mailHeaders);
337 TimeLimiter::prepareMessageConfigurationView($this->configuration);
359 $result->addError(
new Error($exception->getMessage()));
364 if (Integration\Bitrix24\Service::isCloud())
366 if ($mailBody && mb_strpos($mailBody,
'#UNSUBSCRIBE_LINK#') ===
false)
369 $result->addError(
new Error(
Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_ERR_NO_UNSUB_LINK')));
374 &&
$configuration->getOption(
'APPROVE_CONFIRMATION')->getValue() ===
'Y'
375 && !
$configuration->getOption(
'APPROVE_CONFIRMATION_CONSENT')->getValue()
379 $result->addError(
new Error(
Loc::getMessage(
'SENDER_INTEGRATION_MAIL_MESSAGE_ERR_NO_APPROVE_CONFIRMATION_CONSENT')));
385 $this->configuration->getOption(
'LINK_PARAMS')->getValue(),
390 foreach ($utmTags as $utmTag => $value)
399 $emailFrom = $this->configuration->getOption(
'EMAIL_FROM')->getValue();
401 $this->configuration->getOption(
'EMAIL_FROM')->setValue($emailFrom);
403 $trackMail = $this->configuration->getOption(
'TRACK_MAIL')->getValue();
407 $this->configuration->getOption(
'TRACK_MAIL')->setValue(
'N');
409 return Entity\Message::create()
412 ->saveConfiguration($this->configuration);
457 Loader::includeModule(
'fileman');
459 $msg = $this->configuration->getOption(
'MESSAGE')->getValue();
465 if (!isset($template[
'FIELDS']) || !$template[
'FIELDS'][
'MESSAGE'][
'ON_DEMAND'])
470 $templateHtml =
null;
471 if (isset($template[
'FIELDS']) && isset($template[
'FIELDS'][
'MESSAGE']))
473 $templateHtml = $template[
'FIELDS'][
'MESSAGE'][
'VALUE'];
475 if (!$templateHtml && isset($template[
'HTML']))
477 $templateHtml = $template[
'HTML'];
489 if(!Block\
Content\Engine::create($document)->setContent($msg)->fill())
499 StyleInliner::inlineDocument($document);
500 $msg = $document->saveHTML();
504 $msgTmp = Block\Editor::replaceCharset($msg,
'#SENDER_MAIL_CHARSET#',
true);
510 if (Option::get(
'sender',
'use_inliner_for_each_template_mail',
'N') !=
'Y')
512 $this->configuration->set(
'BODY', $msg);
524 if (!$this->configuration->get(
'TEMPLATE_TYPE') || !$this->configuration->get(
'TEMPLATE_ID'))
529 return Templates\Selector::create()
530 ->withMessageCode(static::CODE)
531 ->withTypeId($this->configuration->get(
'TEMPLATE_TYPE'))
532 ->withId($this->configuration->get(
'TEMPLATE_ID'))
543 static $headerList =
null;
544 if ($headerList ===
null)
546 $headerList = array();
548 $optionHeaders = Option::get(
'sender',
'mail_headers',
'');
549 $optionHeaders = !empty($optionHeaders) ? unserialize($optionHeaders, [
'allowed_classes' =>
false]) : array();
550 foreach ($optionHeaders as $optionHeader)
552 $optionHeader = trim($optionHeader);
558 $optionHeaderParts = explode(
':', $optionHeader);
559 $optionHeaderName = isset($optionHeaderParts[0]) ? $optionHeaderParts[0] :
'';
560 $optionHeaderName = trim($optionHeaderName);
561 $optionHeaderValue = isset($optionHeaderParts[1]) ? $optionHeaderParts[1] :
'';
562 $optionHeaderValue = trim($optionHeaderValue);
563 if (!$optionHeaderName || !$optionHeaderValue)
568 $headerList[$optionHeaderName] = $optionHeaderValue;
572 foreach ($headerList as $optionHeaderName => $optionHeaderValue)
574 $headers[$optionHeaderName] = $optionHeaderValue;