"Recipient address required" even after encoding the raw message

853 views Asked by At

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' <[email protected]>\n
To: 'Jane Doe' <[email protected]>\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/[email protected]/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

There are 1 answers

1
Fabio Lama On BEST ANSWER

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.