Apps script for Gmail - search for exact subject

烂漫一生 提交于 2019-12-10 21:23:27

问题


I get every day multiple automatic emails. One has the subject 'Daily Report' and one has the subject 'Daily Report details'. This is the script I was using, but once the emails started coming without chronological order, I sometimes catch the wrong one.

 var threads = GmailApp.search('Daily Report') //search gmail with the given query(partial name using * as a wildcard to find anything in the current subject name).
 var msgs = GmailApp.getMessagesForThreads(threads);

Is there a way to tell the search that I want the mail with exact subject 'Daily Report' and not the one with 'Daily Report Details'?

Thanks


回答1:


Like @Pierre-Marie Richard and @Cooper mentioned, you can use the built-in Gmail search functions. Here are a list of the Gmail Search Functions, like @Cooper mentioned you may be best using something like:

var threads = GmailApp.search('subject:"Daily Report"-Details')
var msgs = GmailApp.getMessagesForThreads(threads);

The quotes ("") work as an exact match and the minus ('-') is to exclude a word. If that still doesn't work let me know and I will look further into it.

Good Luck :)



来源:https://stackoverflow.com/questions/44174943/apps-script-for-gmail-search-for-exact-subject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!