Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SmtpTransport.php

function SmtpTransport::doSend

Overrides AbstractTransport::doSend

File

vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php, line 203

Class

SmtpTransport
Sends emails over SMTP.

Namespace

Symfony\Component\Mailer\Transport\Smtp

Code

protected function doSend(SentMessage $message) : void {
    if (microtime(true) - $this->lastMessageTime > $this->pingThreshold) {
        $this->ping();
    }
    if (!$this->started) {
        $this->start();
    }
    try {
        $envelope = $message->getEnvelope();
        $this->doMailFromCommand($envelope->getSender()
            ->getEncodedAddress(), $envelope->anyAddressHasUnicodeLocalpart());
        foreach ($envelope->getRecipients() as $recipient) {
            $this->doRcptToCommand($recipient->getEncodedAddress());
        }
        $this->executeCommand("DATA\r\n", [
            354,
        ]);
        try {
            foreach (AbstractStream::replace("\r\n.", "\r\n..", $message->toIterable()) as $chunk) {
                $this->stream
                    ->write($chunk, false);
            }
            $this->stream
                ->flush();
        } catch (TransportExceptionInterface $e) {
            throw $e;
        } catch (\Exception $e) {
            $this->stream
                ->terminate();
            $this->started = false;
            $this->getLogger()
                ->debug(\sprintf('Email transport "%s" stopped', __CLASS__));
            throw $e;
        }
        $mtaResult = $this->executeCommand("\r\n.\r\n", [
            250,
        ]);
        $message->appendDebug($this->stream
            ->getDebug());
        $this->lastMessageTime = microtime(true);
        if ($mtaResult && ($messageId = $this->parseMessageId($mtaResult))) {
            $message->setMessageId($messageId);
        }
    } catch (TransportExceptionInterface $e) {
        $e->appendDebug($this->stream
            ->getDebug());
        $this->lastMessageTime = 0;
        throw $e;
    }
}
RSS feed
Powered by Drupal