用于查看电子邮件并将电子表格附件复制到 Google 云端硬盘的 Google 脚本
每个星期一,我都会收到一份发送到我的 Gmail 的报告,其中包含两个 Google 电子表格附件。
我每周都需要打开这些附件并将其复制到我的 Google 云端硬盘中的特定文件夹中。
我想要一个能够
1) 的 Google 脚本。每个星期一查看我的 Gmail 并搜索一封新电子邮件,其主题为:“截至 [日期] 的每小时资历报告和截至 [日期] 的每小时终止报告”| 注意:同一用户每周发送报告
2)。复制这两个附件,然后通过文件夹 ID 将副本移动到 Google 文件夹。
我对 Google 脚本相当陌生,在网上查找时,我还没有找到太多可以帮助我实现这种自动化的东西。有谁对如何解决这个问题有任何想法?谢谢你!
Every Monday, I get a report sent to my Gmail that has two Google Spreadsheet attachments.
I need to open these attachments and make a copy of them into a specific folder in my Google Drive each week.
I would like a Google Script that will
1). Look through my Gmail each Monday and search for a new email with the subject: "Hourly Seniority Report as of [date] and Hourly Termination Report as of [date]" | Note: The same user sends out the report each week
2). Make a copy of the two attachments and move the copy to a Google Folder via the Folder's ID.
I'm fairly new to Google scripting and looking online, I haven't found much that could help me with this automation. Does anyone have any ideas on how to approach this? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果文件附加到电子邮件
GmailApp.search()
函数来实现(您可以阅读有关它的更多信息< a href="https://developers.google.com/apps-script/reference/gmail/gmail-app#searchquery" rel="nofollow noreferrer">此处)。请注意,这将返回一个线程列表,每个线程依次包含一个消息列表。只要没有其他具有该主题的电子邮件(似乎是这种情况),抓取第一个线程的第一条消息(我的方法)就可以正常工作。Folder
对象的createFile()
函数来完成(您可以在此处阅读有关它的更多信息)。您可以使用getFolderById()
函数获取所需的Folder
对象(您可以阅读有关它的更多信息 此处)。如果该文件是共享云端硬盘的链接
,在这种情况下,该文件将不会显示为电子邮件的附件,因此此处无法采用之前使用的相同方法。不过,该文件将在您的云端硬盘中显示为与我共享。我在这里使用的方法是收集与您共享的所有文件(使用
searchFiles()
函数,您可以阅读有关它的更多信息此处),然后扫描电子邮件的纯文本以查找该电子邮件中是否提及了每个文件的 ID(意思是它是共享)。当然,您可以将此脚本设为时间限制触发脚本,以便根据您的意愿每天执行一次。在这种情况下,脚本应动态获取执行日期,以每天收集正确的电子邮件。您可以在此处详细了解触发器。
If the file is attached to the email
GmailApp.search()
function (you can read more about it here). Note that this will return a list of threads that each one in turn will contain a list of messages. Grabbing the first message of the first thread (my approach) will work fine as long as there are no other emails with that subject (which seems to be the case).createFile()
function of aFolder
object (you can read more about it here). You can get the desiredFolder
object by using thegetFolderById()
function (you can read more about it here).If the file is a link to a shared Drive
In this case, the file will not show up as an attachment to the email, so the same method used before cannot be employed here. However, the file will show up as shared with me in your Drive. The approach I used here is to gather all the files that are shared with you (using the
searchFiles()
function, you can read more about it here) and then scan the email's plain text to find whether or not each file's id was mentioned in that email (meaning it was shared).Of course, you can make this script a Time bound trigger script so that it will execute once a day if you wish so. In that case, the date of the execution should be grabbed dynamically by the script to gather the correct email each day. You can read more about triggers here.