我想转发标记为star的某些邮件。我只想发送普通正文(而不是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 Drive。
getAttachments()
GmailApp.sendEmail()
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()});
如果我误解了你的问题,对不起。