feature/add-attachments #2

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

View File

@ -5,6 +5,8 @@ namespace Bluescale\Mail;
use Bluescale\Mail\BluescaleMailTemplate; use Bluescale\Mail\BluescaleMailTemplate;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class BluescaleMailApi class BluescaleMailApi
{ {
@ -37,6 +39,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)
@ -48,6 +51,16 @@ class BluescaleMailApi
$template->recipients[] = [ $template->recipients[] = [
'address' => $notifiable->email 'address' => $notifiable->email
]; ];
if (count($attachments) > 0) {
$formatted_attachmments = [];
foreach ($attachments as $attachment) {
$file = new UploadedFile($attachment->path, $attachment->fileName, 'application/octet-stream', null, null, false);
$formatted_attachmments[] = $file;
}
$template->attachments($formatted_attachmments);
}
} }
try { try {