阅读电子邮件附件到R [英] Reading Email Attachment to R

查看:163
本文介绍了阅读电子邮件附件到R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R来阅读Outlook附件.我的参考资料在这里:使用Outlook电子邮件从Outlook电子邮件中下载附件R

I am using R to read an Outlook attachment. My reference is here: Download attachment from an outlook email using R

这是我的电子邮件的屏幕截图:

This is a screenshot of what my email looks like:

这是每天发送给我的.

This gets sent to me daily.

当我尝试提取此附件时,这就是我的处理方式:

When I try extracting this attachment this is how I went about it:

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.

您知道如何解决此问题吗?

Any idea how I can fix this issue?

谢谢!

推荐答案

尝试将Sys.sleep(5)(如果不起作用,请尝试Sys.sleep(10))放入另存为resultsresults$Item(1)$ReceivedTime()之间.我认为这之间需要时间进行处理.

Try putting Sys.sleep(5) (if that doesn't work, try Sys.sleep(10))in between saving as results, and results$Item(1)$ReceivedTime(). I think it needs time to process in between.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆