Skip to content

Instantly share code, notes, and snippets.

@calaveraInfo
Last active April 20, 2017 07:25
Show Gist options
  • Save calaveraInfo/84fbfe33fb4604ca861e769ad8bfec20 to your computer and use it in GitHub Desktop.
Save calaveraInfo/84fbfe33fb4604ca861e769ad8bfec20 to your computer and use it in GitHub Desktop.
Google apps script to forward email as html attachment (ie Email to Kindle integration)
function forwardAsAttachment() {
var label = GmailApp.getUserLabelByName("test");
var labelDone = GmailApp.getUserLabelByName("testdone");
/* GmailApp.search('label:test'); */
var threads = label.getThreads();
for (var h = 0; h < threads.length; h++) {
var messages = threads[h].getMessages();
i = messages.length-1;
var subject = messages[i].getSubject();
Logger.log(subject);
var body = messages[i].getBody();
var bodyAttachment = Utilities.newBlob(body, MimeType.HTML, "article.html");
MailApp.sendEmail({
to: "...",
subject: subject,
attachments: [bodyAttachment]
/* htmlBody: body,*/
});
threads[h].removeLabel(label);
threads[h].addLabel(labelDone)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment