• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/mail/sender.php
  • Класс: BitrixMainMailSender
  • Вызов: Sender::applyCustomSmtp
static function applyCustomSmtp($event)
{
	$headers = $event->getParameter('arguments')->additional_headers;
	$context = $event->getParameter('arguments')->context;

	if (empty($context) || !($context instanceof Context))
	{
		return;
	}

	if ($context->getSmtp() && $context->getSmtp()->getHost())
	{
		return;
	}

	if (preg_match('/X-Bitrix-Mail-SMTP-Host:/i', $headers))
	{
		return;
	}

	$eol = Mail::getMailEol();
	$eolh = preg_replace('/([a-f0-9]{2})/i', 'x1', bin2hex($eol));

	if (preg_match(sprintf('/(^|%1$s)From:(.+?)(%1$s([^s]|$)|$)/is', $eolh), $headers, $matches))
	{
		$address = new Address(preg_replace(sprintf('/%ss+/', $eolh), '', $matches[2]));
		if ($address->validate())
		{
			if ($customSmtp = static::getCustomSmtp($address->getEmail()))
			{
				$context->setSmtp($customSmtp);
			}
		}
	}
}