0

I'm having an issue with sending emails via the Gmail API. I followed the instructions as specified by various sources:

Message:

From: 'John Doe' <john.doe@gmail.com>\n
To: 'Jane Doe' <jane.doe@gmail.com>\n
Subject: This is a subject\n
Did you receive this message?

(I tried both with and without ', including specifying the email address directly)

I encoded this as base64 (url safe) and add it to the "raw" field of the body. Note that I pass the full JSON as the body.

{
   "raw":"RnJvbTogJ0pvaG4gRG9lJyA8am9obi5kb2VAZ21haWwuY29tPgpUbzogJ0phbmUgRG9lJyA8amFuZS5kb2VAZ21haWwuY29tPgpTdWJqZWN0OiBUaGlzIGlzIGEgc3ViamVjdApEaWQgeW91IHJlY2VpdmUgdGhpcyBtZXNzYWdlPw=="
}

(I tried both with and without padding)

I'm using the following HTTP headers:

   "headers":{
      "content-type":"message/rfc822",
      "authorization":"Bearer ya..."
   }

After doing a POST request to https://gmail.googleapis.com/upload/gmail/v1/users/john.doe@gmail.com/messages/send I get the following response:

{
  "error": {
    "code": 400,
    "message": "Recipient address required",
    "errors": [
      {
        "message": "Recipient address required",
        "domain": "global",
        "reason": "invalidArgument"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

EDIT: The official Google docs aren't really helpful regarding language neutrality.

  • 1
    Does this answer your question? [GMail API - Can I send email using the Service Account?](https://stackoverflow.com/questions/33233694/gmail-api-can-i-send-email-using-the-service-account) – Dharman Sep 30 '20 at 11:30

1 Answers1

-1

As it turns out, you cannot send email with a service account. The official Google support page literally tells you to use a third party service:

https://cloud.google.com/compute/docs/tutorials/sending-mail/

So I just went old-school and use SMTP. Works great.

  • If you found an answer in another post on Stack Overflow then we usually do not post a new answer, we close the question as a duplicate. If the duplicate was the solution to your problem please accept it and delete the answer. You could also leave this answer if you edit it to add more information that was not present in the old answer. – Dharman Sep 30 '20 at 11:31