protected function buildMessage(EmailEntity $email)
    {
        // Create attachments array
        $attachments = json_decode($email->getAttachments(), true) ?: [];

        // Convert Mandrill format to Mailgun format
        $attachments = array_map(
            function ($attachment) {
                if (isset($attachment['content'])) {
                    $attachment['data'] = base64_decode(
                        Arr::remove($attachment, 'content')
                    );
                }
                if (isset($attachment['name'])) {
                    $attachment['filename'] = Arr::remove($attachment, 'name');
                }
                if (isset($attachment['type'])) {
                    $attachment['contentType'] = Arr::remove($attachment, 'type');
                }

                return attachment;
            },
            $attachments
        );

        if ($email->getSenderName()) {
            $from = "{$email->getSenderName()} <{$email->getSenderEmail()}>";
        } else {
            $from = $email->getSenderEmail();
        }

        if ($email->getTemplateName()) {
            $html = $this->templateService->renderHbsForEmail(
                $email->getTemplateName(),
                $email->getTemplateData() ? json_decode($email->getTemplateData(), true) : []
            );
        } else {
            $html = $email->getMessage();
        }

        $message = [
            'html'        => $html,
            'subject'     => $email->getSubject(),
            'from'        => $from,
            'to'          => $this->filterThroughWhitelist($email->getRecipientEmail()),
            'attachments' => $attachments,
        ];

        if ($email->getHeaders()) {
            $headers = [];
            foreach (json_decode($email->getHeaders(), true) as $key => $value) {
                $headers["h:{$key}"] = $value;
            }
            $message['headers'] = $headers;
        }

        return $message;
    }