library(RDCOMClient)
## create outlook object
OutApp <- COMCreate("Outlook.Application")
我想从名为“AUX”的 Outlook 文件夹中检索今天的电子邮件。
解析电子邮件的标题,如果满足某些条件,我想解析电子邮件的内容以获取某些字符串。
我设法从 R 写了一封电子邮件并将其发送出去,但到目前为止无法检索电子邮件。
这是我通过反复试验得出的一些示例代码:
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。
要获取有关 Outlook 对象模型的更多信息,我建议您要么获取Ken Slovak 的 Outlook 2007 书 https://rads.stackoverflow.com/amzn/click/com/0470049944(仍然适用于更高版本的 Outlook),或者查看我的个人网站,http://www.gregthatcher.com http://www.gregthatcher.com(查看“脚本”部分——我多年来一直在编译这些脚本。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)