Have been working on an Apps Script to bring Gmail message information (sender, subject, link, attachment) into a Google Sheet, but not able to bring the title of the attachment over successfully (attachment name field in Google Sheet reads like [Ljava.lang.Object;@127afe9
; it appears to be related to the attachments array, but I cannot figure it out. Have tried the solutions offered in What does "[Ljava.lang.Object;@" mean?, but no luck.
function emailToSheet() {
var label = GmailApp.getUserLabelByName('New TODO'); // Find messages with label
var changeLabel = GmailApp.getUserLabelByName('TODO'); // Change message label to
var ss = SpreadsheetApp.openById('xxxx'); // Append to spreadsheet
var sh = ss.getSheetByName("Email"); //On this sheet
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 sent = messages[j].getDate();
var from = messages[j].getFrom();
var subject = messages[j].getSubject();
// Get attachment name
var attachments = messages[j].getAttachments();
var attachmentName = [];
for (var k=0; k<attachments.length; k++) {
var attachmentName = attachments[k].getName();
}
var messageId = messages[j].getId();
var messageUrl = "https://mail.google.com/mail/u/0/#inbox/" + messageId;
ss.appendRow([sent, from, subject, attachmentName, messageUrl])
}
threads[i].removeLabel(label);
threads[i].addLabel(changeLabel);
}
}