An example of the script is as follow:
function forwardMail() {
var threads = GmailApp.search("before:2009/07/01 after:2009/06/30"); // second search string.
for (var i in threads) {
var lastMsg = threads[i].getMessageCount(); //get last message
var messages = threads[i].getMessages();
var message = messages[0]; //first mail in the thread
//var message = messages[lastMsg-1]; // last mail in the thread
message.forward("strovek@seagate.com");
}
}
Notes:
In the example above, you can use messages[0] to select the first message in a thread or messages[lastMsg-1] for the last message in a thread. The last message will usually contains most of the replies of the threads if the participants are the same throughout the thread conversations.
To make sure you get the mails you want to forward, test the search expression in Gmail first.
No comments:
Post a Comment