0
votes

Im trying to create a gmail draft using gmail API and open it in a new tab.

When i try to open a draft using the following url : https://mail.google.com/mail/u/0/#drafts/ draft id , from a external web it does not open the draft. Instead it lists the drafts. If i do the same in a Gmail tab it works as expected.

You can reproduce it following this steps

  1. Chose any draft and copy its message id , you can use this
  2. Create a url joining https://mail.google.com/mail/u/0/#drafts/ + the message id you got in the last step.
  3. Open a new tab in Chrome and paste it, it will send you to your draft list.
  4. If you paste the same url in the the same tab it will open the draft.

More information about the problem

It does not work with https://mail.google.com/mail/u/0/#drafts/?compose= neither

Chrome console throws this error when i try to open a draft from another tab console error

I noticed if you open a draft the url is like this one https://mail.google.com/mail/u/0/#drafts?compose=JHrtffLJpZXxNwzKGMhcjvjBrqfPRwKWvkvJbtWpRffXldzxkNQhmkkBWJsHPbdSPdDgBVKpHKZMNtCVFgXrhwMCVjCdCRqTLJhGvqrXNKFZmJDGZ , this url works also to open the draft editor from other tabs, but where does the compose value come from?

I know it is not a API error or problem but if somebody had the same problem and know any way to solve it i will apreciate.

So the question is, how can i create a url to open a gmail draft using Gmail API ?

2

2 Answers

3
votes

The way to make this url changed, now it works like this:

mail.google.com/mail/#inbox?compose=draft.message.id

If you list your drafts you get

{
  "drafts": [
    {
      "id": "r5632827412362757569",
      "message": {
        "id": "174f4fa0dd96af123",
        "threadId": "174f4f59344d6321"
      }
    }
  ],
  ...
}

So, to open this draft you need the following url :

mail.google.com/mail/#inbox?compose=174f4fa0dd96af123

2
votes

Your goal:

To be able to open a browser tab directly focused on a specific draft of your choosing, from the drafts in your mailbox. (Correct me if I'm wrong).

Background:

  1. You noticed that drafts have a "compose" parameter visible in the url when focused within the UI.
  2. The drafts resource doesn't include the "compose" parameter, so we can't get it from the API, and it also isn't equal to the draft id.

Conclusion:

Since the parameter needed is not publicly available via API, you can't achieve your goal at the moment. You can request the feature to Google directly by creating a "Feature Request" for the Gmail API. Here's the link Issue Tracker.