api_key = $api_key; } /** * @param BluescaleMailTemplate $template * @param $notifiable * @return \Psr\Http\Message\StreamInterface * @throws BluescaleMailException */ public function send($template, $notifiable): StreamInterface { $url = config('bmail.api_url') ?? 'https://bluescale.email/api/project/template/send'; $client = new Client(); $notifiable_recipient = false; if (is_object($notifiable) && $notifiable_email = $notifiable->email) { $recipients = $template->recipients; if (count($recipients) > 0) foreach ($recipients as $recipient) if (!empty($recipient['address'])) if ($notifiable_email == $recipient['address']) $notifiable_recipient = true; } if (!$notifiable_recipient) $template->recipients[] = [ 'address' => $notifiable->email ]; try { return $client->request('post', $url, [ 'form_params' => $template, 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_key, 'Accept' => 'application/json' ] ])->getBody(); } catch(\Exception $e) { throw new BluescaleMailException($e->getMessage()); } } }