Skip to content

Commit

Permalink
Merge pull request #71 from utopia-php/feat-email-extra-params
Browse files Browse the repository at this point in the history
updates cc and bcc for email
  • Loading branch information
abnegate authored Dec 5, 2023
2 parents a3ebf9d + 005045b commit b2d4b03
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/Utopia/Messaging/Adapter/Email/Mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ protected function process(EmailMessage $message): string

if (! \is_null($message->getCC())) {
foreach ($message->getCC() as $cc) {
$body['cc'] = "{$body['cc']},{$cc['name']}<{$cc['email']}>";
if (! empty($cc['name'])) {
$body['cc'] = "{$body['cc']},{$cc['name']}<{$cc['email']}>";
} else {
$body['cc'] = "{$body['cc']}, <{$cc['email']}>";
}
}
}

if (! \is_null($message->getBCC())) {
foreach ($message->getBCC() as $bcc) {
$body['bcc'] = "{$body['bcc']},{$bcc['name']}<{$bcc['email']}>";
if (! empty($bcc['name'])) {
$body['bcc'] = "{$body['bcc']},{$bcc['name']}<{$bcc['email']}>";
} else {
$body['bcc'] = "{$body['bcc']}, <{$bcc['email']}>";
}
}
}

Expand Down
28 changes: 20 additions & 8 deletions src/Utopia/Messaging/Adapter/Email/Sendgrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,31 @@ protected function process(EmailMessage $message): string

if (! \is_null($message->getCC())) {
foreach ($message->getCC() as $cc) {
$personalizations[0]['cc'][] = [
'name' => $cc['name'],
'email' => $cc['email'],
];
if (! empty($cc['name'])) {
$personalizations[0]['cc'][] = [
'name' => $cc['name'],
'email' => $cc['email'],
];
} else {
$personalizations[0]['cc'][] = [
'email' => $cc['email'],
];
}
}
}

if (! \is_null($message->getBCC())) {
foreach ($message->getBCC() as $bcc) {
$personalizations[0]['bcc'][] = [
'name' => $bcc['name'],
'email' => $bcc['email'],
];
if (! empty($bcc['name'])) {
$personalizations[0]['bcc'][] = [
'name' => $bcc['name'],
'email' => $bcc['email'],
];
} else {
$personalizations[0]['bcc'][] = [
'email' => $bcc['email'],
];
}
}
}

Expand Down
20 changes: 18 additions & 2 deletions src/Utopia/Messaging/Adapter/SMS/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Utopia\Messaging\Adapter\SMS as SMSAdapter;
use Utopia\Messaging\Messages\SMS as SMSMessage;
use Utopia\Messaging\Response;

class Mock extends SMSAdapter
{
Expand All @@ -24,7 +25,7 @@ public function getName(): string

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

/**
Expand All @@ -34,6 +35,10 @@ public function getMaxMessagesPerRequest(): int
*/
protected function process(SMSMessage $message): string
{
$response = new Response($this->getType());

$response->setDeliveredTo(\count($message->getTo()));

$result = $this->request(
method: 'POST',
url: 'http://request-catcher:5000/mock-sms',
Expand All @@ -49,6 +54,17 @@ protected function process(SMSMessage $message): string
]),
);

return \json_encode($result['response']);
if ($result['statusCode'] === 200) {
$response->setDeliveredTo(\count($message->getTo()));
foreach ($message->getTo() as $to) {
$response->addResultForRecipient($to);
}
} else {
foreach ($message->getTo() as $to) {
$response->addResultForRecipient($to, 'Unknown Error.');
}
}

return \json_encode($response->toArray());
}
}

0 comments on commit b2d4b03

Please sign in to comment.