下面是一些示例代码,我通过反复试验工作:
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
}
}
很抱歉,但我不知道为什么有些COM对象的要求参数(如主题(1)),但别人不会(比如Body())。这在Outlook 2013中适用于我,但它也应该适用于2007年以来的所有Outlook版本。
要获取有关Outlook对象模型的更多信息,我建议您要么获得Ken Slovak's Outlook 2007 book(对于更高版本的Outlook仍然相关),要么检查我的个人网站http://www.gregthatcher.com(请查看“脚本”部分 - 我)
您好格雷格,$文件夹名称似乎不是一个适当的R的语法,我省略$符号,但你再次使用它的'文件夹'分配。是否有一个原因? –
“$”是一个错误。我编辑了答案。另外,请确保您没有以管理员身份运行RStudio。您应该使用普通帐户运行RStudio。 –
你能解释一下吗?你在哪里可以找到让你知道什么COM对象可以提取的文档? –