skip to Main Content

I am trying to make a chrome extension for gmail and am currently tinkering around with InboxSDK but I am unable to figure out how do I access email body from the inbox list itself(without opening the email) to add labels depending on the content.

I get the threadRowView object but I am unsure what to do after that to get more details of the mail.
I think getElement() might be able to help somehow but I am unable to make sure how do I extract the mail from raw gmail DOM.
https://inboxsdk.github.io/inboxsdk-docs/lists/

2

Answers


  1. Chosen as BEST ANSWER

    I am yet to find a way to do this directly only by using InboxSDK but there is a workaround which can help you get shorter descriptive text from the email which is seen on the inbox list.

    InboxSDK.load('1.0', 'YOUR_APP_ID').then(function(sdk) {
      sdk.Lists.registerThreadRowViewHandler(function(threadRowView) {
        var threadElement = threadRowView.getElement();
        var descriptiveText = threadElement.textContent;
        // do something based on the text
      });
    });
    

    Documentation

    I will update the answer if I am able to a better solution but I think one way to this properly should be using Official Gmail API and get the message using messageID.


  2. To access the email body from the inbox list using InboxSDK, you can use the ThreadView.getThreadData() method to get the thread data, which includes the message data for each message in the thread. From there, you can access the message body using the getBodyText() method.

    Here’s some sample code to get you started:

    InboxSDK.load('1.0', 'YOUR_APP_ID').then(function(sdk) {
      sdk.Lists.registerThreadRowViewHandler(function(threadRowView) {
        var threadView = threadRowView.getThreadView();
        threadView.getThreadData().then(function(threadData) {
          var messages = threadData.getMessages();
          for (var i = 0; i < messages.length; i++) {
            var message = messages[i];
            var body = message.getBodyText();
            // Do something with the body, like add labels based on content
          }
        });
      });
    });
    

    official documentation

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search