我在 R 中运行一项日常任务,该任务从我的 Outlook 中检索一封电子邮件(附加了一个 csv 文件),对 csv 文件执行一些分析,并将生成的数据帧写入我公司的本地驱动器。有些早上我发现文件没有送达,根据日志,原因是以下错误:
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred.
Execution halted
我找不到发生这种情况的日子和不发生这种情况的日子的任何模式。一旦我手动触发任务,它通常运行良好。
我在其他问题中看到过这个错误,但这些问题与通过 Outlook 发送附件有关,我没有这样做。以下是我用于访问 Outlook 和检索数据的代码:
library(RDCOMClient)
outlook_app <- COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
"Inbox",
"urn:schemas:httpmail:subject = 'My_Subject'"
)
Sys.sleep(5)
results <- search$Results()
for (i in 1:results$Count()) {
if (as.Date("1899-12-30") + floor(results$Item(i)$ReceivedTime())
== as.Date(strptime(Sys.time(),format = "%Y-%m-%d"))) {
email <- results$Item(i)
}
}
attachment_file <- tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)
data <- read.csv(attachment_file,sep=",",fileEncoding="UCS-2LE")