我使用R来阅读Outlook附件。我的参考资料如下:Download attachment from an outlook email using R
这是我的电子邮件的截图:
每天都会发送给我。
当我尝试提取此附件时,我就是这样做的:
install.packages('RDCOMClient')
library(RDCOMClient)
outlook_app <- COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
"Inbox",
"urn:schemas:httpmail:subject = 'DDM Report #107047216 : \"Nick_ACS_Brand_All_FloodLights\" from Nicholas Knauer'"
)
results <- search$Results()
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()) {
if (as.Date("1899-12-30") + floor(results$Item(i)$ReceivedTime())
== as.Date("2017-12-17")) {
email <- results$Item(i)
}
}
attachment_file <- tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)
data <- read.csv(attachment_file, skip = 10)
运行results$Item(1)$ReceivedTime()
后,出现此错误:
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
我知道如何解决这个问题吗?
谢谢!
答案 0 :(得分:0)
尝试在保存为Sys.sleep(5)
和Sys.sleep(10)
之间放置results
(如果这不起作用,请尝试results$Item(1)$ReceivedTime()
)。我认为需要时间来处理。
results <- search$Results() # Saves search results into results object
Sys.sleep(5) # Wait a hot sec!
results$Item(1)$ReceivedTime() # Received time of first search result
as.Date("1899-12-30") + floor(results$Item(1)$ReceivedTime()) # Received date
# Iterates through results object to pull out all of the items
for (i in 1:results$Count()) {
if (as.Date("1899-12-30") + floor(results$Item(i)$ReceivedTime())
== as.Date(Sys.Date())) {
email <- results$Item(i)
}
}