First of all, I am not familiar with coding. I have a code that I use to pull certain information from Gmail based on the labels. Now the problem is, the code does not include a line to have the name of attachment. It would be really helpful if someone can write an additional code for that.
Below is the code that I use.. I tried adding the code var attachment = messages[j].getAttachments().getName();
to it, but doesn't work.
var label = GmailApp.getUserLabelByName("NAME OF LABEL");
var threads = label.getThreads();
for (var i = threads.length - 1; i >=0; i--){
var messages = threads[i].getMessages();
for (var j = 0; j <messages.length; j++){
var message = messages[j];
extractDetails(message);
}
}
function extractDetails(message){
var dateTime = message.getDate();
var subjectText = message.getSubject();
var senderDetails = message.getFrom();
var bodyContents = message.getPlainBody();
var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
activeSheet.appendRow([dateTime, senderDetails, subjectText, bodyContents]);
}
getAttachments()
returns ALL of the attachments (even if there is only one attachment) in an array. So you need to loop through each item in the array to get the attachment name(s). There's a good example of this in the documentation.