Can I get a URL link to a Gmail draft using the Gmail API?

余生颓废 提交于 2019-12-05 05:33:37

No, creating the URL manually is currently your best option. You can drop the u/0/ if you want and Gmail will automatically use the first authenticated account.

No, there is not a way for you to automatically sign a user into Gmail.

For exposing URL to a draft created by API, this works:

...
final Gmail.Users.Drafts.Create request = gmailService.users().drafts().create("me", content);
final Draft response = request.execute();
final String url = "https://mail.google.com/mail/ca/u/0/#drafts/" 
             + response.getMessage().getThreadId() 
...

When the user clicks on it, gmail will translate (and redirect) to a different URL, but opens the correct draft. I however did not find mention of this in the docs, so it might be an unsupported feature that stops working one day.

Credits: @Chris Wood from this SO question stackoverflow.com/q/50124112/455449 (see his comment below question)


Concerning passing authentication info:

  • passing account id is probably not possible
  • passing password in url would be a security nonsense (so I trust it is not possible)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!