Last active
April 20, 2017 07:25
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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