I have specific incoming emails assigned different labels and I have threading (conversation view) disabled in settings. I can enter a search in the web app that returns the specific messages I want,
eg: "label: customer01 label:report"
However using the exact same filter with the API returns the thread and all messages there-in that Google has decided are part of the same conversation (even though in the real world they are not) which means my script processes messages it should not in addition to those it should.
eg: var threads = GmailApp.search(gSearchExp); // where gSearchExp is the aforementioned filter
Is there a way I can search for and return messages, NOT threads?
How about using Gmail API? I think that by using Gmail API, you can retrieve the message with the specific labels. The sample script is as follows.
In order to use this, please enable Gmail API at Advanced Google Services and API console. You can see how to do it at here.
var userId = "me";
var query = "label:customer01 label:report";
var res = Gmail.Users.Messages.list(userId, {q: query});
var ids = res.messages.map(function(e){return e.id});
Logger.log(ids) // Message IDs with the specific labels.
var userId = "me"
to your environment.If I misunderstand your question, please tell me. I would like to modify it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With