• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/mail/smtp/mailer.php
  • Класс: BitrixMainMailSmtpMailer
  • Вызов: Mailer::getInstance
static function getInstance(Context $context): ?Mailer
{
	$key = hash('sha256', serialize($context));
	if (!static::$instances[$key])
	{
		$mail = new Mailer();
		if (!$mail->prepareConfiguration($context))
		{
			return null;
		}

		if ($context->getSmtp())
		{
			$mail->setFrom($context->getSmtp()->getFrom());
		}

		switch ($context->getKeepAlive())
		{
			default:
			case self::KEEP_ALIVE_NONE:
				$mail->SMTPKeepAlive = false;
				break;
			case self::KEEP_ALIVE_ALWAYS:
				$mail->SMTPKeepAlive = true;
				HttpApplication::getInstance()->addBackgroundJob(
					function () use ($mail)
					{
						$mail->smtpClose();
					});
				break;
			case self::KEEP_ALIVE_OPTIONAL:
				$mail->SMTPKeepAlive = true;
				break;
		}

		static::$instances[$key] = $mail;
	}

	return static::$instances[$key];
}