Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/Utopia/Messaging/Adapter/Email/Mailchimp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Utopia\Messaging\Adapter\Email;

use Utopia\Messaging\Adapter\Email as EmailAdapter;
use Utopia\Messaging\Messages\Email as EmailMessage;
use Utopia\Messaging\Response;

class Mailchimp extends EmailAdapter
{
protected const NAME = 'Mailchimp';

public function __construct(
private readonly string $apiKey,
) {
parent::__construct();
}

public function getName(): string
{
return static::NAME;
}

public function getMaxMessagesPerRequest(): int
{
return 1000;
}

protected function process(EmailMessage $message): array
{
$response = new Response($this->getType());

$result = $this->request(
method: 'POST',
url: 'https://mandrillapp.com/api/1.0/messages/send',
headers: [
'Content-Type: application/json',
],
body: [
'key' => $this->apiKey,
'message' => [
'html' => $message->isHtml() ? $message->getContent() : null,
'text' => $message->isHtml() ? null : $message->getContent(),
'subject' => $message->getSubject(),
'from_email' => $message->getFromEmail(),
'from_name' => $message->getFromName(),
'to' => array_map(
fn(array $to) => ['email' => $to['email'], 'name' => $to['name'] ?? ''],
$message->getTo()
),
],
Comment on lines +41 to +51

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Email fields are silently dropped

When an EmailMessage contains CC or BCC recipients, a distinct reply-to address, or attachments, this payload never reads or sends those fields, causing copy recipients to receive nothing, replies to target the sender, and delivered messages to omit their attachments.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Utopia/Messaging/Adapter/Email/Mailchimp.php
Line: 41-51

Comment:
**Email fields are silently dropped**

When an `EmailMessage` contains CC or BCC recipients, a distinct reply-to address, or attachments, this payload never reads or sends those fields, causing copy recipients to receive nothing, replies to target the sender, and delivered messages to omit their attachments.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

],
);

$statusCode = $result['statusCode'];
$responseBody = $result['response'];

if ($statusCode >= 200 && $statusCode < 300) {
$response->setDeliveredTo(\count($message->getTo()));
foreach ($message->getTo() as $to) {
$response->addResult($to['email']);
}
Comment on lines +58 to +62

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Recipient failures reported as delivered

When Mandrill returns HTTP 200 with a recipient marked rejected or invalid, this branch ignores the per-recipient response and records every address as successful, causing deliveredTo and recipient results to report undelivered messages as delivered. HTTP 5xx responses also bypass both branches and return no recipient errors.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Utopia/Messaging/Adapter/Email/Mailchimp.php
Line: 58-62

Comment:
**Recipient failures reported as delivered**

When Mandrill returns HTTP 200 with a recipient marked `rejected` or `invalid`, this branch ignores the per-recipient response and records every address as successful, causing `deliveredTo` and recipient results to report undelivered messages as delivered. HTTP 5xx responses also bypass both branches and return no recipient errors.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

} elseif ($statusCode >= 400 && $statusCode < 500) {
$error = '';
if (\is_array($responseBody) && isset($responseBody['message'])) {
$error = $responseBody['message'];
} elseif (\is_string($responseBody)) {
$error = $responseBody;
}

foreach ($message->getTo() as $to) {
$response->addResult($to['email'], $error ?: 'Unknown error');
}
}

return $response->toArray();
}
}