usable()) { throw new TransportException('Gmail is selected as the mail provider, but no account is connected.'); } try { $token = $this->broker->freshAccessToken($connection); } catch (MailOAuthException $e) { throw new TransportException('Could not get a Google access token: '.$e->getMessage(), 0, $e); } $response = Http::withToken($token)->post('https://gmail.googleapis.com/gmail/v1/users/me/messages/send', [ 'raw' => rtrim(strtr(base64_encode($message->toString()), '+/', '-_'), '='), ]); if (! $response->successful()) { $status = $response->json('error.status'); $detail = $response->json('error.message'); throw new TransportException( 'Gmail refused the message (HTTP '.$response->status() .(is_string($status) && $status !== '' ? ', '.$status : '').')' .(is_string($detail) && $detail !== '' ? ': '.$detail : '.'), ); } } public function __toString(): string { return 'gmail-api'; } }