0
votes

I have created one application in which I am fetching all the mails from inbox of gmail in my application. Now what I want is when user clicks on any of the email in my application, then user should be redirected to actual gmail and email on which user has clicked that should be opened in gmail. So I am achieving that functionality by providing mail.google.com/mail/u/0/#inbox/ link in href tag in my application.

Now problem I am facing here is let's say user has multiple gmail accounts open in browser. As I have provided hard coder url "https://mail.google.com/mail/u/0/#inbox/", it's always opening mail in "0" authuser id. So is there any way that I can get this value dynamically in my application. I checked that how gmail is doing that let's say when I opened first gmail account that url will be mail.google.com/mail/u/0/#inbox. If I open another account then url will be mail.google.com/mail/u/1/#inbox. So insted of 0, now it will be 1.

So I have checked that when we are accessing any gmail api, google is providing with the consent screen and if multiple accounts are opened that google will provide you screen in which you can choose the account. After you choose the account, consent screen will come. So url will be like "https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/gmail.readonly&response_type=code&redirect_uri=http://localhost:8080/web/guest/GmailDashboard&access_type=online&approval_prompt=auto&client_id=19502573792-0fvebvrb4jg1usmn2r0hfka31la8gtfs.apps.googleusercontent.com&hl=en&from_login=1&as=4ded27cb6d28ee3b&pli=1&authuser=0". I want the last parameter authuser in my application.

Any help will be really appreciated.

Thanks and Regards, Abdulbasit F Shaikh.

2

2 Answers

3
votes

A solution is to include a query parameter called authUser that specifies the email account you want to link to:

https://mail.google.com/mail/?authuser[email protected]#all/138d85da096d2126

See the below link:

How can I reliably link to a Gmail conversation given a thread ID if the user is logged into multiple accounts?

0
votes

Instead of providing the hard code url, I think you could give the url below for an access to multiple gmail address dynamically:

https://accounts.google.com/ServiceLoginAuth?continue=http://mail.google.com/gmail&service=mail&[email protected]