You are searching for messages that contain the email anywhere. Use .search('from:user@mail.com')
Google App Script GMail search returns too many messages?
-
04-07-2023 - |
题
I am searching a GMail account for mail adresses, like that:
var threads = GmailApp.search('somemail@example.com');
for(var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for(var j = 0; j < messages.length; j++) {
app.add(app.createLabel("from: " + messages[j].getFrom()));
}
}
The code goes through all the threads found for a given mail address and prints the "from" for each message from each found thread. This should work, but it doesnt. It also returns messages that have nothing to do with the given mail address. I also tried the real GMail search and it does not find the suspicious "froms". It really only happens from the code side.
Is there something wrong with my code?
Thanks!
解决方案
不隶属于 StackOverflow