feature/add-attachments #2

Manually merged
Thifaine merged 12 commits from feature/add-attachments into master 2020-06-09 16:20:07 +02:00
2 changed files with 31 additions and 4 deletions
Showing only changes of commit e0a805cbdb - Show all commits

View File

@ -37,6 +37,7 @@ class BluescaleMailApi
$notifiable_recipient = false; $notifiable_recipient = false;
$notifiable_email = $notifiable->email; $notifiable_email = $notifiable->email;
$recipients = $template->recipients; $recipients = $template->recipients;
$attachments = $template->attachments;
if (count($recipients) > 0) if (count($recipients) > 0)
foreach ($recipients as $recipient) foreach ($recipients as $recipient)
@ -44,14 +45,32 @@ class BluescaleMailApi
if ($notifiable_email == $recipient['address']) if ($notifiable_email == $recipient['address'])
$notifiable_recipient = true; $notifiable_recipient = true;
if (!$notifiable_recipient) if (!$notifiable_recipient)
$template->recipients[] = [ $template->recipients[] = [
'address' => $notifiable->email 'address' => $notifiable->email
]; ];
} }
$files = [];
if (count($attachments) > 0)
foreach ($attachments as $attachment)
$files[] = [
'name' => $attachment['name'],
'contents' => $attachment['content'],
'filename' => $attachment['filename'],
];
try { try {
if (count($attachments) > 0) {
return $client->request('post', $url, [
'multipart' => $files,
'form_params' => $template,
'headers' => [
'Authorization' => 'Bearer ' . $this->api_key,
'Accept' => 'application/json'
]
])->getBody();
}
return $client->request('post', $url, [ return $client->request('post', $url, [
'form_params' => $template, 'form_params' => $template,
'headers' => [ 'headers' => [

View File

@ -26,6 +26,13 @@ class BluescaleMailTemplate implements \JsonSerializable
public $recipients = []; public $recipients = [];
/** /**
* The attachments for the message
*
* @var array
*/
public $attachments = [];
/**
* The reply address for the message * The reply address for the message
* *
* @var array * @var array
@ -159,6 +166,7 @@ class BluescaleMailTemplate implements \JsonSerializable
'sender' => $this->sender, 'sender' => $this->sender,
'replyTo' => $this->replyTo, 'replyTo' => $this->replyTo,
'recipients' => $this->recipients, 'recipients' => $this->recipients,
'attachments' => $this->attachments,
'parameters' => $this->parameters, 'parameters' => $this->parameters,
]; ];
} }