Reputation: 13213
At the recent Google IO conference new Gmail APIs were announced. Client libraries are missing examples and documentation which is understandable given the short time that has gone by.
UPDATE: It wasn't clear in the original question - I've already tried encoding the whole message as Base64 string.
I'm trying to create a new draft message:
var request = gapi.client.gmail.users.drafts.create({
'message' : {
'raw' : Base64.encode("To: [email protected]\r\nFrom: [email protected]\r\nSubject: my subject\r\n\r\nBody goes here")
// 'raw' : "VG86IHNvbWVndXlAZXhhbXBsZS5jb20KRnJvbTogbXlzZWxmQGV4YW1wbGUuY29tClN1YmplY3Q6IG15IHN1YmplY3QKCkJvZHkgZ29lcyBoZXJl"
// 'raw' : "From: [email protected]\nTo:[email protected]\nSubject:Ignore\n\nTest message\n"
}
});
request.execute(function(response) {
});
Can you please provide me with the correct syntax to do that?
(Base64.encode is coming from http://www.webtoolkit.info/javascript-base64.html - tried using plain text, encoded version on the fly and hardcoded values from other question)
Related questions:
Handy links just for reference:
So I'm trying to find a solution in related questions addressing Ruby and C# by recreating JSON structure but I've reached the point that I need a Rubber Duck or Stack Overflow.
Thank you in advance for providing a hint on how to structure the object passed to the API method.
Upvotes: 0
Views: 2569
Reputation: 7159
The trick is it's not just normal base64 encoding it's WEB SAFE (aka URL SAFE) base64 encoding. It's similar except two characters in the alphabet are different to make sure the entire blob works well in URLs and javascript/json.
Upvotes: 0
Reputation: 13213
While @rds answer is technically correct: "base64 encode complete message", the fully working answer is as follows... The correct structure of the request:
'draft': {
'message': {
'raw': base64EncodedEmail
}
}
Source: https://developers.google.com/gmail/api/v1/reference/users/drafts/create (scroll down and then choose JavaScript from dropdown menu)
I was missing the essential draft property.
Upvotes: 1
Reputation: 26984
Since the question is the same, the answer will be identical:
'raw' should contain the entire (RFC822) email, complete with body and headers.
Upvotes: 0