Skip to content

Instantly share code, notes, and snippets.

@macleginn
Created July 3, 2016 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macleginn/dec6fbff1f51a8e95a0445674d703316 to your computer and use it in GitHub Desktop.
Save macleginn/dec6fbff1f51a8e95a0445674d703316 to your computer and use it in GitHub Desktop.
Put all the messages from a Gmail inbox satisfying a query into a Google document
function collateMessages() {
var searchString = "YOURQUERYHERE";
// A query can be anything that you can enter
// into the Gmail search field:
// "datageddon from:ivan@pochta.net filename:pdf"
// etc.
var doc = DocumentApp.create(searchString);
var threads = GmailApp.search(searchString);
for (var j = 0; j < threads.length; j++) {
var messages = threads[j].getMessages();
for (var i = 0; i < messages.length; i++) {
var txt = messages[i].getPlainBody();
doc.getBody().appendParagraph(txt);
doc.getBody().appendParagraph("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment