如何使用Outlook中的R下载多个附件(全部为CSV)?
我的代码只是读取第一个附件。我无法遍历邮件中存在的所有附件。
将RDCOMClient用作库
library(RDCOMClient)
outlook_app <- COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
"Inbox",
"urn:schemas:httpmail:subject = 'test'"
)
Sys.sleep(5)
results <- search$Results()
Sys.sleep(10)
results$Item(1)$ReceivedTime() # Received time of first search result
as.Date("1899-12-30") + floor(results$Item(1)$ReceivedTime()) # Received date
for (i in 1:results$Count()) {
print(i)
if (as.Date("1899-12-30") + floor(results$Item(i)$ReceivedTime()) == as.Date("2019-04-03")) {
email <- results$Item(i)
}
}
attachment_file <- tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)
data <- read.csv(attachment_file)
无法保存第一个附件以外的附件。