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

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

问题描述


##创建outlook对象
OutApp< - COMCreate(Outlook.Application)

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



我设法写了一封电子邮件从R发送,但到目前为止还没有收到电子邮件。

解决方案

这是我要工作的一些示例代码通过试用错误:

 库(RDCOMClient)

folderName =AUX

##创建outlook对象
OutApp< - COMCreate(Outlook.Application)
outlookNameSpace = OutApp $ GetNameSpace(MAPI)

文件夹< - outlookNameSpace $文件夹(1)$文件夹(folderName)
#检查我们是否有正确的文件夹
文件夹$ Name(1)

电子邮件< - 文件夹$项目

#不能弄清楚如何获取项目数量,所以只要先做10
(我在1:10)
{
subject< - 电子邮件(i)$主题(1)
#用#78替换您正在寻找的电子邮件主题行
if(grepl(# 78,主题)[1]){
打印(电子邮件(i)$ Body())
break
}
}

对不起,但是我不知道为什么这些COM对象中的一些需要参数(像主题(1)),但是其他的没有身体())。这在Outlook 2013上适用于我,但它也可以在2007年的所有版本的Outlook上工作。



要获得有关Outlook对象模型的更多信息,我建议您要么得到肯斯洛伐克的Outlook 2007图书(仍然适用于更高版本的Outlook),或否则请查看我的个人网站, http://www.gregthatcher.com (查看脚本部分 - 我已经编译了很多年了。)


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

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.

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

# Can't figure out how to get number of items, so just doing first 10
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
  } 
}

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.

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天全站免登陆