Relatively new google scripts.
What I am trying to do is
- Select all the specified emails in a label in Gmail
- Save each email as a separate pdf (using subject) and save in a the specified folder in google drive
- Generate a link to that pdf
Save in spreadsheet the
a)Date
b)Subject
c)Plain Body Txt
d)Html Body Txt
e)Link to each pdf file
The following code is generating the points a to d
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var label = GmailApp.getUserLabelByName("MY LABEL");
var threads = label.getThreads();
for (var i=0; i<threads.length; i++)
{
var messages = threads[i].getMessages();
for (var j=0; j<messages.length; j++)
{
var msghtml = messages[j].getBody();
var msgplain = messages[j].getPlainBody();
var sub = messages[j].getSubject();
var dat = messages[j].getDate();
ss.appendRow([dat,sub,msgplain,msghtml])
}
threads[i].removeLabel(label);
}
}
Need to add the functionality to save each file as separate pdf (using) and add link to this sheet
There are already some threads where people are generating the pdfs from the gmail threads
Automatically convert emails with a Gmail label to PDF and send it to an email address
But don't know how to incorporate it into the existing code to make it work.
PS:If it can be made into something that adds any new emails to the sheet that would be awesome