简体   繁体   English

在 Apps 脚本中接收 [Ljava.lang.Object(将附件名称从 Gmail 带到表格)

[英]Receiving [Ljava.lang.Object in Apps Script (bringing attachment name from Gmail to Sheets)

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?][1], but no luck.一直在开发一个应用程序脚本,将 Gmail 消息信息(发件人、主题、链接、附件)导入 Google 表格,但无法成功将附件的标题带入 Google 表格中(Google 表格中的附件名称字段类似于[Ljava.lang.Object;@127afe9 ; 它似乎与附件数组有关,但我无法弄清楚。尝试过[What does "[Ljava.lang.Object;@" mean?][1]中提供的解决方案,但没有运气。

  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);
  }
}```


  [1]: https://stackoverflow.com/questions/31582248/what-does-ljava-lang-object-mean

I'm thinking that you want this:我在想你想要这个:

  var attachmentName = [];
  for (var k=0; k<attachments.length; k++) {
    var attachmentName = attachments[k].getName();
  }

to be this:变成这样:

   var attachmentName = [];
  for (var k=0; k<attachments.length; k++) {
    attachmentName.push(attachments[k].getName());
  }

and maybe this:也许这个:

  ss.appendRow([sent, from, subject, attachmentName, messageUrl])

to be this:变成这样:

  ss.appendRow([sent, from, subject, attachmentName.join(" "), messageUrl])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM