簡體   English   中英

Google腳本:在新郵件中轉發收到的郵件附件

[英]Google Script: Forward received mail-attachements in new Mails

我想轉發某些標記為星號的郵件。 我只想發送簡單的正文(而不是HTML正文),還可以轉發原始附加的文件(如果有)。

我當前的代碼如下所示:

function getMailsAndForward() {
  var thread, subject, body_PLAIN, emails, i;

  emails = GmailApp.search("in:SomeLabel AND in:starred");  
  var count = emails.length;

  if (count == 0)
    return; 

  for (i=0; i<count; i++) {    
    if (emails[i]) 
    {
      thread     = emails[i].getMessages()[0];
      subject    = "[AUTO-FORWARD] " + thread.getSubject();
      body_PLAIN = thread.getPlainBody(); 

      GmailApp.sendEmail("", subject, body_PLAIN, {"bcc": "xx@yy.com, fewmore@here.com"});

      // Unstar Mail... 
      GmailApp.unstarMessage(thread); 
    }
  }
}  

我已經找到了一些在線解決方案,例如關於如何從接收到的郵件中提取附件到GoogleDrive,以及如何將GoogleDrive文件附加到新創建的郵件上。

但是在走這條路線之前,我想問:是否有任何更簡便的方法,而無需事先將附件保存到GoogleDrive中的文件中? 會很方便...

提前致謝!

接下來的修改如何?

您可以使用getAttachments()作為包含blob的數組來檢索附件文件。 帶有斑點的數組用於GmailApp.sendEmail() 這樣,不需要將附件文件另存為Google雲端硬盤。

來自:

GmailApp.sendEmail("", subject, body_PLAIN, {"bcc": "xx@yy.com, fewmore@here.com"});

至 :

GmailApp.sendEmail("", subject, body_PLAIN, {"bcc": "xx@yy.com, fewmore@here.com", "attachments": thread.getAttachments()});

注意 :

  • 在此修改后的腳本中,如果沒有附件文件,則發送不帶附件文件的郵件。

如果我誤解了您的問題,對不起。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM