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_email = $notifiable->email;
$recipients = $template->recipients;
$attachments = $template->attachments;
if (count($recipients) > 0)
foreach ($recipients as $recipient)
@ -44,17 +45,35 @@ class BluescaleMailApi
if ($notifiable_email == $recipient['address'])
$notifiable_recipient = true;
if (!$notifiable_recipient)
$template->recipients[] = [
'address' => $notifiable->email
];
}
$files = [];
if (count($attachments) > 0)
foreach ($attachments as $attachment)
$files[] = [
'name' => $attachment['name'],
'contents' => $attachment['content'],
'filename' => $attachment['filename'],
];
try {
return $client->request('post', $url, [
'form_params' => $template,
'headers' => [
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, [
'form_params' => $template,
'headers' => [
'Authorization' => 'Bearer ' . $this->api_key,
'Accept' => 'application/json'
]

View File

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