How to close gmail compose dialog programmatically in chrome extension

I have replaced the “Send” button in the compose dialog with my “Send” button and using “Gmail API” to send the email.

I am able to send the email and get the response.

Now to make it more user-friendly, I want to close the compose dialog after my email is sent (similarly when the Gmail closes the dialog when email is sent). But I am unable to do so.

NOTE: When the email is sent successfully using “Gmail API”, I am deleting the draft for that email also.

Getting 401 status while sending email using Gmail API in Chrome extension

I am getting the raw data of the drafted from Gmail API “get” method and sending it using Gmail API “send” method.

'var url = 'https://www.googleapis.com/gmail/v1/users/me/messages/id?
     format=raw&alt=json&access_token=' + token;
 url = url.replace("id", emailId);
 var x = new XMLHttpRequest();
 x.open('GET', url , true);
 x.send();
 x.onload = function() {
     var jsonRes = JSON.parse(x.response);
     sendEmail(jsonRes.raw);
 }


function sendEmail(raw) {
    if (raw) {
        var request = new XMLHttpRequest();
        var url = 'https://www.googleapis.com/gmail/v1/users/me/messages/send?alt=json&access_token=' + token;
        params = "raw=" + raw;
        request.open('POST', url , true);
        request.setRequestHeader("Authorization", "Bearer " + token);
        request.setRequestHeader("Content-type", "application/json");
        request.send(params);
        request.onload = function() {
            if (200 === request.status) {
                alert("Email sent successfully");
        }
    }
}`

I am getting 401 status.

If I am sending this raw data from API page itself, then it is sent successfully. Therefore the raw data is correct.

I am missing something while sending the email. Please help!

Retrieve Gmail access_token

I need to find the google access_token that is sent to the browser after user logs in to GMail. It should be somewhere among cookies or in a browser local storage.

The problem is that the
chrome.identity.launchWebAuthFlow({url: authURL, interactive: true}, cb)
wants from the user to choose the account again even when he is already logged in to GMail.

What I really want is something similar to Microsoft Outlook Office.context.mailbox.getCallbackTokenAsync that allows to the logged user using Microsoft REST API without authenticating again.

Get listener for incoming email in gmail and get its content

I’m working on a chrome extension in which, I’m logging the emails in an external system using Gmail API to get the contents.

I want to log the reply given to those emails also. For this, I need a listener for whenever an email arrives in my Inbox.

I’m not able to implement the listener.
Also, please share an alternate solution.

Note: I need the implementation in pure JS.

window.GLOBALS[17] is null in the new Gmail UI while it is present for the old Gmail UI

I have a Chrome extension which uses a library called gmail.js which is sort of dependent on the window.GLOBALS[17] object from the Gmail window however in the new UI of gmail, Gmail seems to have removed the GLOBALS[17] which is equal to null now, Now I have no way to access the data that was present inside the GLOBALS[17] object, I have searched, looked and tried everything but do not seem to have an alternative to GLOBALS[17] object

The GLOBALS[17] is still available on the old Gmail UI

When seen in old Gmail UI

And is null in new Gmail UI

Wheen seen from new Gmail UI

Without this I cannot know vital information like whether the email is in conversation view and so on

Why was this removed? Is there an alternative?

Get the Message Id or thread Id immediately after sent gmail

Can I get the message id or thread id immediately after sent gmail using google script or gmail API.?

chrome extension call to gmail api

I am really new creating chrome extensions. I am trying to use Gmail API in my extension to get the Thread Id from sent email folder. I have used this tutorial:
https://medium.com/streak-developer-blog/how-to-use-the-gmail-api-in-a-chrome-extension-a272b2405b57
When I use the function getThreads(query, labels),
https://gist.github.com/omarstreak/7908035c91927abfef59

I did not get nothing. Also when I review the background console appear this error:
Unchecked runtime.lastError while running identity.getAuthToken: OAuth2 request failed: Service responded with error: ‘bad client id: {0}’

I have created my own client_id and I put it in my manifest.

 "oauth2": {
"client_id": "27599747390-.................apps.googleusercontent.com",
"scopes": [
  "https://www.googleapis.com/auth/gmail.modify"
]

},

Have someone some tutorial or sample that works about using Gmail API in chrome extensions?.

Get email senders in batch from Gmail API for over 10k emails

I’m making an Chrome Extension which interacts with Gmail API.
Basically it needs to extract email senders from emails that match some keyword.
Problem is that sometimes there are over 10K emails matching this keyword.
I utilize gapi.client.gmail.users.messages.list to fetch all emails that match entered keyword, but this only returns email and thread IDs, so I need to call gapi.client.gmail.users.messages.get for each email ID retrieved from messages.list.
So there are over 10K requests to Gmail API, and I run into ERR_INSUFFICIENT_RESOURCES error in Chrome. To prevent this error, I set some timeout between calls to messages.get but then it would take ages to complete…

Is there some recommended way to get this amount of emails from Gmail API?

Chrome Extenion with Google API Basics

I am attempting to make a chrome extension and I want to integrate the Gmail API. I need to use OAuth to authenticate a user. When I am getting the OAuth credential, I am given an option based on the type of application I am making. I suspect a chrome extension would be a chrome app, as opposed to a web application, as it is running locally and not being served over the web.

Am I correct in my assumptions?

  • The API calls should be coming from background.js
  • The manifest should contain the following sections:
  • "content_scripts": [
    {
    ...
    "js":["js/main.js", "js/background.js"]
    }
    ],
    ...
    "background": {
    "scripts": [
    "js/background.js",
    "js/client.js"]
    },
    "content_security_policy": "script-src https://.google.com 'unsafe-eval'; object-src 'self'",
    "oauth2": {
    "client_id": MY CLIENT ID,
    "scopes": [
    "scope: 'https://mail.google.com/'"
    ]
    },
    "permissions": [
    "background",
    "identity",
    "tabs",
    "https://www.googleapis.com/
    ",
    "https://.googleusercontent.com/",
    "https://mail.google.com/"
    ]
    ...

    Am I missing any crucial details?

    Is there any google API which could save gmail message attachments to google drive?

    How can I save gmail message attachments to google drive. Is there any such google API?