如何使用RDCOMClient按日期检索电子邮件

时间:2020-02-20 07:55:54

标签: r outlook rdcomclient

我正在尝试仅从Outlook收件箱中特别是文件夹中检索“今天”收到的电子邮件。我将如何做到这一点?下面的以下代码使我可以从收件箱中提取所有电子邮件,但是我仅对今天收到的电子邮件感兴趣。我要在代码中添加什么?

folderName <-  "Folder2"

## create outlook object
OutApp <- COMCreate("Outlook.Application")
outlookNameSpace <-  OutApp$GetNameSpace("MAPI")

folder <- outlookNameSpace$GetDefaultFolder(6)
fld <-  folder$folders(folderName)
cnt <-  fld$Items()$Count()

emails <- fld$items
resp <-  data.frame(sno = 1:cnt,Text = "",stringsAsFactors=FALSE)

for(i in seq(cnt)){
  d <-  as.data.frame(emails(i)$Body(), stringsAsFactors=FALSE)
  resp$Text[i] = d[1]
  resp$Sender[i] = emails(i)[['SenderName']]
  resp$To[i] = emails(i)[['To']]
  resp$sub[i] = emails(i)[['subject']]
}

1 个答案:

答案 0 :(得分:0)

Items.Find/FindNextItems.Restrict[ReceivedTime] >= '02/20/2020 00:00am'之类的查询一起使用