0

I'm trying to access gmail messages through google appscript, but I can only find methods to access threads and messages inside those threads. How do I retrieve messages that are not threaded?

Currently I'm using the getInboxThreads() and getMessagesForThread() functions because I cannot find ways of getting non-threaded messages in the inbox.

1 Answers1

1
  var message = GmailApp.search('your search text', 0, 1)[0]
                .getMessages()[0];
  var messageDate = message.getDate();  

  messagebody = message
                .getPlainBody();

That code block gets the first message of the first thread matching the search field. I can understand why it's somewhat confusing, but it's important to understand that, at least in gmail world, a thread does not necessarily have more than one message in it. Every message in gmail is part of a thread. Kind of like a directory or folder with only one file in it.

The messageDate line is just one example of what else you can do once you've identified the message. You can replace "PlainBody" with just "Body" if you want the rich text instead of plaintext.

ballenf
  • 894
  • 10
  • 19
  • Why is it that when I `getInboxThreads()` and then get all of the messages in each of those threads, some messages in my inbox do not show up? – Rishabh Bector Jun 27 '16 at 17:32
  • That's a different problem / question than the one you posed above. And kind of impossible to answer with the information provided. I'd suggest providing your code and example messages from your inbox that don't show. That is, if searches on this topic don't turn up answers for you. Sorry I can't be of help on this question, but hope that my answer above answers your initial question. Edited to add -- will the above code get the message if you craft the search text to match one of the "missing" messages? – ballenf Jun 27 '16 at 18:25