How to send a message successfully using the new Gmail REST API? -


i'm trying test new gmail rest api.

in api explorer possible authorize requests using oauth 2.0 , execute request, i.e. send message.

first authorized. enter image description here

i'm using following test data (and of course used valid to email address):

{        "raw": "c2vuzgluzybhig1hawwgdxnpbmcgr21hawwgukvtvcbbuek=",      "payload": {       "headers": [         { "name": "to",      "value": "info@something.com"   },         { "name": "from",    "value": "taifunbaer@gmail.com" },         { "name": "subject", "value": "test gmail rest api"  }       ],      "mimetype": "text/plain"     } } 

i 200 ok , following result back, looks fine.

{   "id": "146dee391881b35b",   "threadid": "146dee391881b35b", } 

however, mail not sent , can find message nobody@gmail.com in inbox instead;: "an error occurred, message has not been sent."

enter image description here

questions:
1. did test successfully?
2. have add other parameter running?



edit: there 2 different http request methods,

  1. the upload uri media upload requests, and
  2. the metadata uri metadata-only requests

the api explorer supports metadata requests only, means plain-text messages without attachment, , i'm trying do.

got it!

after reading rfc 2822 specification found out, complete message needs passed in raw parameter, see example:

from: john doe <jdoe@machine.example>  to: mary smith <mary@example.net>  subject: saying hello  date: fri, 21 nov 1997 09:55:06 -0600  message-id: <1234@local.machine.example>  message hello. so, "hello". 

so after base64 encoding complete message, passing in raw parameter without using other parameter, works fine.

edit 1:
@amit mentioned, must web-safe base64 encoded, see https://code.google.com/p/stringencoders/wiki/websafebase64

so convert base64 alpha format "web-safe" following changes recommended:

+ --> - (char 62, plus dash) / --> _ (char 63, slash underscore) = --> * padding 

to convert + - , /to _ sufficient me.

edit 2:
answer question of @hjulle here example: need userid , in request body raw parameter. let's assume, email address jdoe@machine.example

first base64 encode complete message (see above) using online encoder , string:

rnjvbtogsm9obibeb2ugpgpkb2vabwfjagluzs5legftcgxlpiakvg86ie1hcnkgu21pdgggpg1h cnlazxhhbxbszs5uzxq+iaptdwjqzwn0oibtyxlpbmcgsgvsbg8gckrhdgu6iezyaswgmjegtm92 ide5otcgmdk6ntu6mdyglta2mdagck1lc3nhz2utsuq6idwxmjm0qgxvy2fslm1hy2hpbmuuzxhh bxbszt4kclroaxmgaxmgysbtzxnzywdligp1c3qgdg8gc2f5ighlbgxvlibtbywgikhlbgxvii4= 

now convert + - , /to _ , get

rnjvbtogsm9obibeb2ugpgpkb2vabwfjagluzs5legftcgxlpiakvg86ie1hcnkgu21pdgggpg1h cnlazxhhbxbszs5uzxq-iaptdwjqzwn0oibtyxlpbmcgsgvsbg8gckrhdgu6iezyaswgmjegtm92 ide5otcgmdk6ntu6mdyglta2mdagck1lc3nhz2utsuq6idwxmjm0qgxvy2fslm1hy2hpbmuuzxhh bxbszt4kclroaxmgaxmgysbtzxnzywdligp1c3qgdg8gc2f5ighlbgxvlibtbywgikhlbgxvii4= 

now pass in raw parameter of api explorer.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -