getOriginalMessage()); $envelope = $message->getEnvelope(); $headers = []; $headersToBypass = ['from', 'to', 'cc', 'bcc', 'reply-to', 'sender', 'subject', 'content-type']; foreach ($email->getHeaders()->all() as $name => $header) { if (in_array($name, $headersToBypass, true)) { continue; } $headers[$header->getName()] = $header->getBodyAsString(); } $attachments = []; if ($email->getAttachments()) { foreach ($email->getAttachments() as $attachment) { $attachmentHeaders = $attachment->getPreparedHeaders(); $contentType = $attachmentHeaders->get('Content-Type')->getBody(); $disposition = $attachmentHeaders->getHeaderBody('Content-Disposition'); $filename = $attachmentHeaders->getHeaderParameter('Content-Disposition', 'filename'); if ($contentType == 'text/calendar') { $content = $attachment->getBody(); } else { $content = str_replace("\r\n", '', $attachment->bodyToString()); } $item = [ 'content_type' => $contentType, 'content' => $content, 'filename' => $filename, ]; if ($disposition === 'inline') { $item['content_id'] = $attachment->hasContentId() ? $attachment->getContentId() : $filename; } $attachments[] = $item; } } try { $result = $this->resend->emails->send([ 'from' => $envelope->getSender()->toString(), 'to' => $this->stringifyAddresses($this->getRecipients($email, $envelope)), 'cc' => $this->stringifyAddresses($email->getCc()), 'bcc' => $this->stringifyAddresses($email->getBcc()), 'reply_to' => $this->stringifyAddresses($email->getReplyTo()), 'headers' => $headers, 'subject' => $email->getSubject(), 'html' => $email->getHtmlBody(), 'text' => $email->getTextBody(), 'attachments' => $attachments, ]); throw_if(isset($result['statusCode']) && $result['statusCode'] != Response::HTTP_OK, Exception::class, $result['message']); } catch (Exception $exception) { throw new TransportException( sprintf('Request to Resend API failed. Reason: %s.', $exception->getMessage()), is_int($exception->getCode()) ? $exception->getCode() : 0, $exception ); } $messageId = $result->id; $email->getHeaders()->addHeader('X-Resend-Email-ID', $messageId); } /** * Get the recipients without CC or BCC. */ protected function getRecipients(Email $email, Envelope $envelope): array { return array_filter($envelope->getRecipients(), function (Address $address) use ($email) { return in_array($address, array_merge($email->getCc(), $email->getBcc()), true) === false; }); } /** * Get the string representation of the transport. */ public function __toString(): string { return 'resend'; } }