I am trying to send an email through my system via Gmail API integration, but I receive an error i.e,
Google_Service_Exception { "error": { "errors": [ { "domain": "global", "reason": "invalidArgument", "message": "Recipient address required" } ], "code": 400, "message": "Recipient address required" } }
Here is the code in Laravel:
$obj = new \Google_Service_Gmail_Message ();
$raw = "MIME-Version: 1.0\n\r
From: Muhammad Bilal <[email protected]>\n\r
To: Umer Sheikh <[email protected]>\n\r
Subject: SIMPLE TEXT EMAIL\n\r
Date: Thu, 5 Mar 2020 18:45:33 +0500\n\r
Message-ID: <[email protected]>\n\r
Content-Type: text/plain; charset=\"UTF-8\"\n\r
\n\r
NO BODY";
$raw = rtrim(strtr(base64_encode($raw), '+/', '-_'), '=');
$obj->setRaw($raw);
$obj->setId('1234');
$obj->setInternalDate(null);
$obj->setLabelIds(null);
$payload = new \Google_Service_Gmail_MessagePart ();
$body = new \Google_Service_Gmail_MessagePartBody ();
$body->setData('test');
$body->setSize('1');
$payload->setBody($body);
$obj->setPayload($payload);
$results = $service->users_messages->send($user, $obj);