I'm using the Google OAuth 2.0 Playground and attempting to send an email. The autentication is working fine. Here is the very simple message I'm trying to send (email address changed to prevent spam):
to: 'Michael To' <FakeMichael@gmail.com> from: 'John From' <JohnF@mydomain.com> subject: 'Test Message' htmlBody: '<b>HI!</b><br>Test Message'
I convert that to Base64 RFC 822 using VBA which gets me this (I've tried swapping the "+" and the "-" per other StackOverflow posts but to no avail):
dG86ICdNaWNoYWVsIFRvJyA8RmFrZU1pY2hhZWxAZ21haWwuY29tPg1mcm9tOiAnSm9obiBGcm9tJyA8Sm9obkZAbXlkb21haW4uY29tPg1zdWJqZWN0OiAnVGVzdCBNZXNzYWdlJw1odG1sQm9keTogJzxiPkhJITwvYj48YnI-VGVzdCBNZXNzYWdlJw==
In the Playground my method is POST and I've added 2 headers:
raw: and the Base64 string above (no quotes or anything)
Content-Type: message/rfc822 <I added this because I kept getting an a different error. Putting this prevetned that error>
Request URI (removed the https cause SO won't let me post more than 2 links)://www.googleapis.com/upload/gmail/v1/users/me/messages/send
I click "send the request" and get an OK response:
Here is my request:
POST /upload/gmail/v1/users/me/messages/send HTTP/1.1
Host: www.googleapis.com
Raw: <string above>
Content-length: 0
Content-type: message/rfc822
Authorization: Bearer <my token>
Response:
HTTP/1.1 200 OK
Alternate-protocol: 443:quic,p=1
Content-length: 91
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Vary: Origin, X-Origin
Server: UploadServer ("Built on Jun 6 2015 11:14:45 (1433614485)")
Etag: "YAnoF_dHYOakPARISZQhTvRsqto/nwevNUuzaUU_lB19L-UhrwaaUSM"
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Wed, 10 Jun 2015 15:59:36 GMT
Content-type: application/json; charset=UTF-8
{
"labelIds": [
"SENT"
],
"id": "14dde32bc92c9XYZ",
"threadId": "14dde32bc92c9XYZ"
}
However, when I go to my Gmail sent mail folder, the message is there but nothing is in the To, Subject, or Body is field: See Screenshot
I have to imagine this is something simple, but as I'm new to the Google Gmail API, MIME, and dealing with Raw Base64 stuff, I'm not having much luck.
Thanks in advance for any assistance.
--- EDIT PER THOLLE'S Response ---
That helps! I removed the raw base64 string header and put:
From: 'John From' <JohnF@mydomain.com>
Subject: Test Message
To: 'Michael To' <FakeMichael@gmail.com>
Test Message
into the "Enter request body" and it sends, which is great!
Three Follow up questions:
- Are there any security risks or limitations (max length? I see there might be a 2mb limitation but that would be a lot of text.) sending it this way (in the body) opposed to a raw Base64 string in the header?
- (I'll dig more on this) How do I make the message body HTML? Does the content type of "Content-Type: message/rfc822" prevent me from being able to send it HTML? Sending it HTML is a requirement for this application and I can't have two content types, is there an HTML parameter I can use or am I out of luck?
- (I'll do homework on this as well) How do I include an attachment, say a PDF file, with the email?
Thanks again!