125 $headers = $message->getConfiguration()->get(
'HEADERS');
126 $headers = is_array($headers) ? $headers : array();
127 $fields = $message->getFields();
128 $preparedConsentLink =
'';
129 $unsubLink = $message->getUnsubTracker()->getLink();
130 if (!isset($fields[
'UNSUBSCRIBE_LINK']))
132 $fields[
'UNSUBSCRIBE_LINK'] = $unsubLink;
136 if (!preg_match(
'/^http:|https:/', $unsubLink))
140 $headers[
'List-Unsubscribe'] =
'<'.$unsubLink.
'>';
141 $headers[
'List-Unsubscribe-Post'] =
'List-Unsubscribe=One-Click';
144 $fields[
'SENDER_MAIL_CHARSET'] = $message->getCharset();
146 if (Integration\Bitrix24\Service::isCloud())
148 $headers[
'X-Bitrix-Mail-Count'] = $message->getTransport()->getSendCount() ?: 1;
149 $recipientData = $message->getRecipientData();
150 if ($recipientData[
'CONTACT_IS_SEND_SUCCESS'] !==
'Y')
152 $headers[
'X-Bitrix-Mail-Unverified'] = 1;
156 $linkParameters = $message->getConfiguration()->get(
'LINK_PARAMS');
160 parse_str($linkParameters, $parametersTmp);
161 if(is_array($parametersTmp))
163 $clickUriParameters = $message->getClickTracker()->getUriParameters();
164 $message->getClickTracker()->setUriParameters(
165 array_merge($clickUriParameters, $parametersTmp)
170 $mailAttachment = array();
171 $messageAttachment = $message->getConfiguration()->get(
'ATTACHMENT');
172 $messageAttachment = is_array($messageAttachment) ? $messageAttachment : array();
173 foreach ($messageAttachment as $key => $file)
175 if (is_numeric($file) && $file > 0)
180 if (is_array($file) && File::isFileExists($file[
'tmp_name']))
182 $mailAttachment[] = array(
183 'PATH' => $file[
'tmp_name'],
184 'ID' => md5($file[
'tmp_name']),
185 'CONTENT_TYPE' => File::getFileContents($file[
'tmp_name']),
186 'NAME' => ($file[
'name'] ?:
'some_file'),
190 unset($messageAttachment[$key]);
193 $canTrackMail = $message->getConfiguration()->get(
'TRACK_MAIL', $this->
canTrackMails());
194 $mailMessageParams = array(
196 'FIELDS' => $this->prepareFields($fields, $message),
198 'BODY_TYPE' =>
'html',
199 'EMAIL_FROM' => $this->
getCleanMailAddress($message->getConfiguration()->get(
'EMAIL_FROM')),
200 'EMAIL_TO' =>
'#EMAIL_TO#',
201 'PRIORITY' => $message->getConfiguration()->get(
'PRIORITY'),
202 'SUBJECT' => $message->getConfiguration()->get(
'SUBJECT'),
203 'MESSAGE' => str_replace(
'#CONSENT_LINK#', $preparedConsentLink, $message->getConfiguration()->get(
'BODY')),
204 'MESSAGE_PHP' => $message->getConfiguration()->get(
'BODY_PHP'),
205 'FILE' => $messageAttachment
207 'SITE' => $message->getSiteId(),
208 'CHARSET' => $message->getCharset(),
210 $mailMessage = Mail\EventMessageCompiler::createInstance($mailMessageParams);
211 $mailMessage->compile();
213 if (is_array($mailMessage->getMailAttachment()))
215 $mailAttachment = array_merge($mailAttachment, $mailMessage->getMailAttachment());
219 'TO' => $mailMessage->getMailTo(),
220 'SUBJECT' => static::replaceTemplate($mailMessage->getMailSubject()),
221 'BODY' => $mailMessage->getMailBody(),
222 'HEADER' => $mailMessage->getMailHeaders() + $headers,
223 'CHARSET' => $mailMessage->getMailCharset(),
224 'CONTENT_TYPE' => $mailMessage->getMailContentType(),
226 'ATTACHMENT' => $mailAttachment,
227 'LINK_PROTOCOL' => $this->getSenderLinkProtocol(),
228 'LINK_DOMAIN' => $message->getSiteServerName(),
229 'TRACK_READ' => $canTrackMail ? $message->getReadTracker()->getArray() :
null,
230 'TRACK_CLICK' => $canTrackMail ? $message->getClickTracker()->getArray() :
null,
233 $linkDomain = $message->getReadTracker()->getLinkDomain();
236 $mailParams[
'LINK_DOMAIN'] = $linkDomain;
240 $eventMailParams = $mailParams;
241 $eventMailParams[
'MAILING_CHAIN_ID'] = $message->getConfiguration()->get(
'LETTER_ID');
242 $event =
new Main\Event(
'sender',
'OnPostingSendRecipientEmail', [$eventMailParams]);
244 foreach ($event->getResults() as $eventResult)
246 if($eventResult->getType() == Main\EventResult::ERROR)
251 if(is_array($eventResult->getParameters()))
253 $eventMailParams = array_merge($eventMailParams, $eventResult->getParameters());
256 unset($eventMailParams[
'MAILING_CHAIN_ID']);
257 $mailParams = $eventMailParams;
259 return Mail\Mail::send($mailParams);
396 $agreement = $this->getAgreement((
int)$message->getConfiguration()->get(
'APPROVE_CONFIRMATION_CONSENT'));
403 $builder->set(
'POSTING_ID', $message->getId());
404 $builder->set(
'CONSENT_ID', $agreement->getId());
405 $buildedMessage = $builder->buildMessage();
407 $contentBody = Security\Sanitizer::fixReplacedStyles($agreement->getText());
408 $contentBody = Security\Sanitizer::sanitizeHtml($contentBody, $agreement->getText());
410 $template = \Bitrix\Sender\Preset\Templates\Consent::getTemplateHtml();
411 $body = \Bitrix\Sender\Preset\Templates\Consent::replaceTemplateHtml($template, [
412 'APPROVE_BTN_TEXT' => $agreement->getLabelText(),
413 'CONSENT_BODY' => $contentBody,
414 'CONSENT_FOOTER' =>
'',
415 'APPLY_URL' => $buildedMessage[
'C_FIELDS'][
'SENDER_CONSENT_APPLY'],
416 'REJECT_URL' => $buildedMessage[
'C_FIELDS'][
'SENDER_CONSENT_REJECT'],
419 $mailMessageParams = array(
423 'BODY_TYPE' =>
'html',
424 'EMAIL_FROM' => $this->
getCleanMailAddress($message->getConfiguration()->get(
'EMAIL_FROM')),
425 'EMAIL_TO' => $buildedMessage[
'C_FIELDS'][
'EMAIL'],
426 'PRIORITY' => $message->getConfiguration()->get(
'PRIORITY'),
427 'SUBJECT' =>
Loc::getMessage(
'SENDER_INTEGRATION_MAIL_CONSENT_SUBJECT'),
429 'MESSAGE_PHP' => $message->getConfiguration()->get(
'BODY_PHP'),
431 'SITE' => $message->getSiteId(),
432 'CHARSET' => $message->getCharset(),
434 $mailMessage = Mail\EventMessageCompiler::createInstance($mailMessageParams);
435 $mailMessage->compile();
438 'TO' => $mailMessage->getMailTo(),
439 'SUBJECT' => static::replaceTemplate($mailMessage->getMailSubject()),
440 'BODY' => $mailMessage->getMailBody(),
441 'HEADER' => $mailMessage->getMailHeaders(),
442 'CHARSET' => $mailMessage->getMailCharset(),
443 'CONTENT_TYPE' => $mailMessage->getMailContentType(),
445 'CONTEXT' => $this->getMailContextForMessage($message),
448 return Mail\Mail::send($mailParams);