从Outlook将最新的Zip文件下载到R-远程托管

时间:2018-12-18 19:16:01

标签: r outlook cron rdcomclient

我想将我的r脚本托管在服务器上,以便创建cron作业。我的r脚本在本地计算机上调用我的Outlook应用程序,并提取具有特定主题名称的最新电子邮件,然后将zip文件下载/提取到R中。

下面的代码:

##Load all packages
library(readr)
library(RDCOMClient)
library(jsonlite)

##Load Data From Email
##File location and Email must be changed for each users unique file name and file path
outlook_app <- COMCreate("Outlook.Application")
search <- outlook_app$AdvancedSearch(
  "Inbox",
  "urn:schemas:httpmail:subject = 'Subject Name'"
)
Sys.sleep(5) 
results <- search$Results() # Saves search results into results object
Sys.sleep(5) 

##Retrieve Most Recent Email
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)
  }
}

##Save to Temp File
attachment_file <- tempfile()
email$Attachments(1)$SaveAsFile(attachment_file)

##Automatically Determine csv file name
file_name<-unzip(attachment_file,list=TRUE)
csv_file<-file_name$Name

##Read csv File from Temp Directory
file_extract <- read_csv(unz(attachment_file,csv_file), skip = 8)

当前可以在我的计算机上正常运行,但是我认为这不能远程运行,因为它正在计算机上调用Outlook应用程序。有人能为此目的远程调用Outlook吗?

0 个答案:

没有答案