将附件从 Outlook 下载到 R

Downloading attachment from Outlook into R

根据格雷格·撒切尔 (Greg Thatcher) 对 的回答(已接受的回答),我编写了一些代码来搜索我的收件箱并查找我每天收到的电子邮件报告。代码以 -

开头
library(RDCOMClient)

folderName = "Inbox"

OutApp = COMCreate("Outlook.Application")
outlookNameSpace = OutApp$GetNameSpace("MAPI")
folder = outlookNameSpace$Folders(1)$Folders(folderName)
emails = folder$Items

这在上周工作正常,但系统通常会在周末重新启动,而现在这不起作用,我不知道为什么。我在代码片段 outlookNameSpace$Folders(1)$Folders(folderName) -

的倒数第二行收到错误
<checkErrorInfo> 80020009 
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.

但是,在尝试排除故障时,我遇到了 Download attachment from an outlook email using R 我用它写出了 -

library(RDCOMClient)

OutApp = COMCreate("Outlook.Application")
search = OutApp$AdvancedSearch("Inbox", "urn:schemas:httpmail:subject = 'Finding Memo - Specific Theme'")

这似乎行得通,因为我在 search$Results()$Count() 时得到了正确的数字。

问题是我不能(或不知道如何)在我的流程中使用第二种方法,因为虽然电子邮件报告主题的开头部分保持不变,但结尾不断变化。第一种方法允许我在电子邮件的主题上使用 grepl()

是否有人可以帮助我了解导致第一种方法失败的原因或指导我修改第二种方法以使用 grepl()

while the beginning part of the subject of the email report stays the same, the end keeps changing.

您可以将 like% 结合使用,然后:

library(RDCOMClient)
OutApp <- COMCreate("Outlook.Application")
search <- OutApp$AdvancedSearch("Inbox", "urn:schemas:httpmail:subject like 'Finding Memo%'")
while (search$Results()$Count() == 0) TRUE 
for (x in seq_len(search$Results()$Count())) {
  print(search$Results()$Item(x)$Subject())
}

This was working last week (...), and now this is not working. (...) If someone could help me understand what is causing first method to break

由于它不可重现并且您没有提供有关更改内容的信息,因此这将很困难。