Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google REST API - message in an RFC 2822 formatted and base64url encoded string

I try the use the - try it of Google REST API - Users.messages: send .

There is there a required parameter - raw -

The entire email message in an RFC 2822 formatted and base64url encoded string. Returned in messages.get and drafts.get responses when the format=RAW parameter is supplied.

I checked about RFC 2822 format and seems it should displayed as the sample here , then I encoded it the base64URL with this encoder and paste it the raw field of the try it and I get - Invalid value for ByteString: http://ostermiller.org/calc/encode.html .

Can you provide me a correct RFC 2822 format and its corresponding base64URL which it would work in the above try it ?

like image 263
URL87 Avatar asked Mar 18 '15 10:03

URL87


1 Answers

An example mail could look like this:

From: [email protected]
To: [email protected]
Subject: Subject Text

The message text goes here

Open up the Developer Tools in your browser and Base64 encode it and replace all + with -, replace all / with _, and remove the trailing = to make it URL-safe:

btoa(
  "From: [email protected]\r\n" +
  "To: [email protected]\r\n" +
  "Subject: Subject Text\r\n\r\n" +

  "The message text goes here"
).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');

This will give you the following data:

RnJvbTogc2VuZGVyQGdtYWlsLmNvbQ0KVG86IHJlY2VpdmVyQGdtYWlsLmNvbQ0KU3ViamVjdDogU3ViamVjdCBUZXh0DQoNClRoZSBtZXNzYWdlIHRleHQgZ29lcyBoZXJl

Use this string above as your raw-parameter in the API Explorer to send the mail.

like image 75
Tholle Avatar answered Oct 01 '22 09:10

Tholle