如何使用 R RDCOMClient 检索 Outlook 收件箱电子邮件? [英] How to retrieve Outlook inbox emails using R RDCOMClient?

查看:27
本文介绍了如何使用 R RDCOMClient 检索 Outlook 收件箱电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

library(RDCOMClient)
## create outlook object
OutApp <- COMCreate("Outlook.Application")

我想从名为AUX"的 Outlook 文件夹中检索今天的电子邮件.解析邮件标题,如果满足一定条件,我想解析邮件内容中的某些字符串.

I want to retrieve today's email from an Outlook folder named 'AUX'. Parse through the email's title and if it meets certain conditions, I want to parse the content of the email for certain strings.

我设法从 R 写了一封电子邮件并将其发送出去,但到目前为止无法检索电子邮件.

I managed to write an email from R and send it out but so far not able to retrieve the emails.

推荐答案

以下是我通过反复试验得到的一些示例代码:

Here is some sample code I got to work by trial and error:

library(RDCOMClient)

folderName = "AUX"

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

folder <- outlookNameSpace$Folders(1)$Folders(folderName)
# Check that we got the right folder
folder$Name(1)

emails <- folder$Items

# Just doing first 10, get total number with emails()$Count()
for (i in 1:10)
{
  subject <- emails(i)$Subject(1)
  # Replace "#78" with the text you are looking for in Email Subject line
  if (grepl("#78", subject)[1]){
    print(emails(i)$Body())
    break
  } 
}

抱歉,我不知道为什么这些 COM 对象中的一些需要参数(例如 Subject(1)),而其他的不需要(例如 Body()).这在 Outlook 2013 上对我有用,但它也应该适用于 2007 年以后的所有 Outlook 版本.

Sorry, but I don't know why some of these COM object require parameters (like Subject(1)), but others don't (like Body()). This worked for me on Outlook 2013, but it should also work on all versions of Outlook from 2007 on.

要获得有关 Outlook 对象模型的更多信息,我建议您获取 Ken Slovak 的 Outlook 2007 书籍(仍然与 Outlook 的更高版本相关),或者查看我的个人网站 http://www.gregthatcher.com(查看脚本"部分——我已经编译这些内容很多年了.)

To get more info on the Outlook Object model I would suggest you either get Ken Slovak's Outlook 2007 book (still relevent for later versions of Outlook), or else check out my personal website, http://www.gregthatcher.com (check out the "Scripts" section -- I have been compiling these for many years.)

这篇关于如何使用 R RDCOMClient 检索 Outlook 收件箱电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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