getOriginalMessage()); $graph = new Graph(); $token = $symfony_message->getHeaders()->get('GmailToken')->getValue(); $message->getHeaders()->remove('GmailToken'); $graph->setAccessToken($token); try { $graphMessage = $graph->createRequest('POST', '/users/'.$this->getFrom().'/sendmail') ->attachBody(base64_encode($message->toString())) ->addHeaders(['Content-Type' => 'text/plain']) ->setReturnType(\Microsoft\Graph\Model\Message::class) ->execute(); } catch (\Exception $e) { sleep(5); $graphMessage = $graph->createRequest('POST', '/users/'.$this->getFrom().'/sendmail') ->attachBody(base64_encode($message->toString())) ->addHeaders(['Content-Type' => 'text/plain']) ->setReturnType(\Microsoft\Graph\Model\Message::class) ->execute(); } } private function getFrom() { return 'turbo124@outlook.com.au'; } private function base64_encode($data) { return rtrim(strtr(base64_encode($data), ['+' => '-', '/' => '_']), '='); } public function __toString(): string { return 'office365'; } }