3
votes

I am trying to fetch sent mail associated to a draft mail using gmail api.

I have a messageId of a draft email. I am fetching the draft Id from the browser address bar url (Eg: https://mail.google.com/mail/u/0/#inbox?compose=1570432re9b57469)

After sending the message the email gets moved from the drafts to the sent box. Also the messageId gets changed for the sent mail.

Tried to fetch the draft using gapi.client.gmail.users.drafts javascript gmail api. But got the error "Requested entity was not found".

The message is not sent using gapi. The message is sent using the normal gmail compose window.

Is there any way to get the sent mail id associated to the draft mail using the draft messageId or any other reference?

1
What is the id field in the response of the drafts/send method? Isn't this the message id? https://developers.google.com/gmail/api/v1/reference/users/drafts/sendredneb
The message is not sent using gapiArun D
The message is sent using the normal gmail compose windowArun D
Do you happen to know the value of the Message-Id header?redneb
I know the messageId of the draft email (like 15709ad2dd121212121)Arun D

1 Answers

1
votes

Ok, so here's an idea. When you fetch the ids of the draft message(s), do an extra request (for each draft if there are many of them) using the drafts/get method, with format=metadata parameter to obtain the Message-Id header, which should be persistent. Then, when the message is sent, search for it using the value of that header, by making a request to:

https://www.googleapis.com/gmail/v1/users/me/messages?maxResults=1&q=rfc822msgid:THEACTUALRFC822MESSAGEID