阅读电子邮件附件到R
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了阅读电子邮件附件到R相关的知识,希望对你有一定的参考价值。
我正在使用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.
知道如何解决这个问题吗?
谢谢!
答案
尝试将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)
}
}
以上是关于阅读电子邮件附件到R的主要内容,如果未能解决你的问题,请参考以下文章