Repository: symfony/symfony
File: src/Symfony/Component/Mailer/Bridge/Mailtrap/Transport/MailtrapApiTransport.php (PHP)

Code before:
        #[\SensitiveParameter] private string $token,
        ?HttpClientInterface $client = null,
        ?EventDispatcherInterface $dispatcher = null,
        ?LoggerInterface $logger = null,
    ) {
        parent::__construct($client, $dispatcher, $logger);
    }

    public function __toString(): string
    {
        return \sprintf('mailtrap+api://%s', $this->getEndpoint());
    }

    /**
     * @return $this
     */
    public function setInboxId(mixed $inboxId): static
    {
        $this->inboxId = (int) $inboxId;

        return $this;
    }

    protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $envelope): ResponseInterface
    {
        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/send'.(0 < $this->inboxId ? '/'.$this->inboxId : ''), [
            'json' => $this->getPayload($email, $envelope),
            'auth_bearer' => $this->token,
        ]);

        try {
            $statusCode = $response->getStatusCode();
            $result = $response->toArray(false);
        } catch (DecodingExceptionInterface) {
            throw new HttpTransportException('Unable to send an email: '.$response->getContent(false).\sprintf(' (code %d).', $statusCode), $response);
        } catch (TransportExceptionInterface $e) {
            throw new HttpTransportException('Could not reach the remote Mailtrap server.', $response, 0, $e);
        }

        if (200 !== $statusCode) {
            throw new HttpTransportException(\sprintf('Unable to send email: "%s" (status code %d).', implode(', ', $result['errors']), $statusCode), $response);
        }

        return $response;
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $payload = [
            'from' => self::encodeEmail($envelope->getSender()),
            'to' => array_map(self::encodeEmail(...), $email->getTo()),

Review comment (suggestion):
```suggestion
        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/send'.($this->inboxId ? '/'.$this->inboxId : ''), [
```

Code after:
        ?HttpClientInterface $client = null,
        ?EventDispatcherInterface $dispatcher = null,
        ?LoggerInterface $logger = null,
    ) {
        parent::__construct($client, $dispatcher, $logger);
    }

    public function __toString(): string
    {
        return \sprintf('mailtrap+api://%s%s', $this->host ?: static::HOST, $this->port ? ':'.$this->port : '');
    }

    protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $envelope): ResponseInterface
    {
        $response = $this->client->request('POST', 'https://'.$this->getEndpoint(), [
            'json' => $this->getPayload($email, $envelope),
            'auth_bearer' => $this->token,
        ]);

        try {
            $statusCode = $response->getStatusCode();
            $result = $response->toArray(false);
        } catch (DecodingExceptionInterface) {
            throw new HttpTransportException('Unable to send an email: '.$response->getContent(false).\sprintf(' (code %d).', $statusCode), $response);
        } catch (TransportExceptionInterface $e) {
            throw new HttpTransportException('Could not reach the remote Mailtrap server.', $response, 0, $e);
        }

        if (200 !== $statusCode) {
            throw new HttpTransportException(\sprintf('Unable to send email: "%s" (status code %d).', implode(', ', $result['errors']), $statusCode), $response);
        }

        return $response;
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $payload = [
            'from' => self::encodeEmail($envelope->getSender()),
            'to' => array_map(self::encodeEmail(...), $email->getTo()),
            'cc' => array_map(self::encodeEmail(...), $email->getCc()),
            'bcc' => array_map(self::encodeEmail(...), $email->getBcc()),
            'subject' => $email->getSubject(),
            'text' => $email->getTextBody(),
            'html' => $email->getHtmlBody(),
            'attachments' => $this->getAttachments($email),
        ];

        foreach ($email->getHeaders()->all() as $name => $header) {
            if (\in_array($name, self::HEADERS_TO_BYPASS, true)) {
                continue;