We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I am trying to send email with this code:
require_once ‘Google/Client.php'; require_once ‘Google/Service/Gmail.php'; // service account $service_account_name = ‘SERVICE_EMAIL'; //Email Address $key_file_location = ‘key.p12′; //key.p12 $client = new Google_Client(array(‘use_objects’ => true)); if (isset($_SESSION['service_token'])) { $client->setAccessToken($_SESSION['service_token']); } $key = file_get_contents($key_file_location); $scopes = array( ‘https://mail.google.com’, ‘https://www.googleapis.com/auth/gmail.compose’, ‘https://www.googleapis.com/auth/gmail.modify’, ); $cred = new Google_Auth_AssertionCredentials($service_account_name, $scopes, $key); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $_SESSION['service_token'] = $client->getAccessToken(); $service = new Google_Service_Gmail($client); try { //$message = '<html><body><p style="color: red;">Hello World!</p></body></html>'; $message = 'Hello World!'; // The message needs to be encoded in Base64URL $mime = rtrim(strtr(base64_encode($message), ‘+/’, ‘-_’), ‘=’); $msg = new Google_Service_Gmail_Message(); $msg->setRaw($mime); $service->users_messages->send(“me”, $msg); } catch (Exception $e) { print($e->getMessage()); }
It keeps failing with error:
`` Error calling POST https://www.googleapis.com/gmail/v1/users/me/messages/send: (500) Backend Error
Thank you for your help.
The text was updated successfully, but these errors were encountered:
Looks OK to me (assuming that gmail supports sending from service accounts) - one thing I am aware of is that you may need to use the URLsafe base 64 encode: https://github.com/google/google-api-php-client/blob/master/src/Google/Utils.php#L26 rather than regular base64_encode.
This tracker is for issues with the library itself though - your best bet for gmail specific questions is the Stack Overflow tag: https://stackoverflow.com/questions/tagged/gmail-api
Sorry, something went wrong.
ianbarber
No branches or pull requests
I am trying to send email with this code:
It keeps failing with error:
``
Error calling POST https://www.googleapis.com/gmail/v1/users/me/messages/send: (500) Backend Error
The text was updated successfully, but these errors were encountered: