- Модуль: sender
- Путь к файлу: ~/bitrix/modules/sender/lib/integration/sender/mail/transportmail.php
- Класс: Bitrix\Sender\Integration\Sender\Mail\TransportMail
- Вызов: TransportMail::send
public function send(Message\Adapter $message)
{
$headers = $message->getConfiguration()->get('HEADERS');
$headers = is_array($headers) ? $headers : array();
$fields = $message->getFields();
$preparedConsentLink = '';
$unsubLink = $message->getUnsubTracker()->getLink();
if (!isset($fields['UNSUBSCRIBE_LINK']))
{
$fields['UNSUBSCRIBE_LINK'] = $unsubLink;
}
if ($unsubLink)
{
if (!preg_match('/^http:|https:/', $unsubLink))
{
$unsubLink = $this->getSenderLinkProtocol() . '://' . $message->getSiteServerName() . $unsubLink;
}
$headers['List-Unsubscribe'] = '<'.$unsubLink.'>';
}
$fields['SENDER_MAIL_CHARSET'] = $message->getCharset();
if (Integration\Bitrix24\Service::isCloud())
{
$headers['X-Bitrix-Mail-Count'] = $message->getTransport()->getSendCount() ?: 1;
$recipientData = $message->getRecipientData();
if ($recipientData['CONTACT_IS_SEND_SUCCESS'] !== 'Y')
{
$headers['X-Bitrix-Mail-Unverified'] = 1;
}
}
$linkParameters = $message->getConfiguration()->get('LINK_PARAMS');
if($linkParameters)
{
$parametersTmp = [];
parse_str($linkParameters, $parametersTmp);
if(is_array($parametersTmp))
{
$clickUriParameters = $message->getClickTracker()->getUriParameters();
$message->getClickTracker()->setUriParameters(
array_merge($clickUriParameters, $parametersTmp)
);
}
}
$mailAttachment = array();
$messageAttachment = $message->getConfiguration()->get('ATTACHMENT');
$messageAttachment = is_array($messageAttachment) ? $messageAttachment : array();
foreach ($messageAttachment as $key => $file)
{
if (is_numeric($file) && $file > 0)
{
continue;
}
if (is_array($file) && File::isFileExists($file['tmp_name']))
{
$mailAttachment[] = array(
'PATH' => $file['tmp_name'],
'ID' => md5($file['tmp_name']),
'CONTENT_TYPE' => File::getFileContents($file['tmp_name']),
'NAME' => ($file['name'] ?: 'some_file'),
);
}
unset($messageAttachment[$key]);
}
//set callback entity Id
if (Integration\Bitrix24\Service::isCloud())
{
if ($message->getRecipientId())
{
$this->getMailContext()->getCallback()
->setEntityType('rcpt')
->setEntityId($message->getRecipientId());
}
else
{
$this->getMailContext()->getCallback()
->setEntityType('test')
->setEntityId(time() . '.' . rand(100, 1000));
}
}
$canTrackMail = $message->getConfiguration()->get('TRACK_MAIL', $this->canTrackMails());
$mailMessageParams = array(
'EVENT' => [],
'FIELDS' => $this->prepareFields($fields, $message),
'MESSAGE' => array(
'BODY_TYPE' => 'html',
'EMAIL_FROM' => $this->getCleanMailAddress($message->getConfiguration()->get('EMAIL_FROM')),
'EMAIL_TO' => '#EMAIL_TO#',
'PRIORITY' => $message->getConfiguration()->get('PRIORITY'),
'SUBJECT' => $message->getConfiguration()->get('SUBJECT'),
'MESSAGE' => str_replace('#CONSENT_LINK#', $preparedConsentLink, $message->getConfiguration()->get('BODY')),
'MESSAGE_PHP' => $message->getConfiguration()->get('BODY_PHP'),
'FILE' => $messageAttachment
),
'SITE' => $message->getSiteId(),
'CHARSET' => $message->getCharset(),
);
$mailMessage = Mail\EventMessageCompiler::createInstance($mailMessageParams);
$mailMessage->compile();
if (is_array($mailMessage->getMailAttachment()))
{
$mailAttachment = array_merge($mailAttachment, $mailMessage->getMailAttachment());
}
$mailParams = array(
'TO' => $mailMessage->getMailTo(),
'SUBJECT' => static::replaceTemplate($mailMessage->getMailSubject()),
'BODY' => $mailMessage->getMailBody(),
'HEADER' => $mailMessage->getMailHeaders() + $headers,
'CHARSET' => $mailMessage->getMailCharset(),
'CONTENT_TYPE' => $mailMessage->getMailContentType(),
'MESSAGE_ID' => '',
'ATTACHMENT' => $mailAttachment,
'LINK_PROTOCOL' => $this->getSenderLinkProtocol(),
'LINK_DOMAIN' => $message->getSiteServerName(),
'TRACK_READ' => $canTrackMail ? $message->getReadTracker()->getArray() : null,
'TRACK_CLICK' => $canTrackMail ? $message->getClickTracker()->getArray() : null,
'CONTEXT' => $this->getMailContext(),
);
$linkDomain = $message->getReadTracker()->getLinkDomain();
if ($linkDomain)
{
$mailParams['LINK_DOMAIN'] = $linkDomain;
}
// event on sending email
$eventMailParams = $mailParams;
$eventMailParams['MAILING_CHAIN_ID'] = $message->getConfiguration()->get('LETTER_ID');
$event = new Main\Event('sender', 'OnPostingSendRecipientEmail', [$eventMailParams]);
$event->send();
foreach ($event->getResults() as $eventResult)
{
if($eventResult->getType() == Main\EventResult::ERROR)
{
return false;
}
if(is_array($eventResult->getParameters()))
{
$eventMailParams = array_merge($eventMailParams, $eventResult->getParameters());
}
}
unset($eventMailParams['MAILING_CHAIN_ID']);
$mailParams = $eventMailParams;
return Mail\Mail::send($mailParams);
}