R,RDCOMClient和Outlook:使用共享地址访问收件箱消息 [英] R, RDCOMClient and Outlook: Access inbox messages with shared addresses

查看:78
本文介绍了R,RDCOMClient和Outlook:使用共享地址访问收件箱消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Outlook中有多个收件箱:my.name@abc.com,以及许多共享收件箱,例如team.data@abc.com或team.ba@abc.com.

I have several inboxes in Outlook: my.name@abc.com, plus a number of shared inboxes like team.data@abc.com for example, or team.ba@abc.com.

按照此方法,我正在尝试访问自己收件箱中的电子邮件.

By following this method I am trying to access the emails in my own inbox.

问题在于,有时收件箱访问邮件到my.name@abc.com,有时可能是其他任何一个!我已经看过Omegahat的解释,但是他们的示例主要集中在excel上,并且我没有VB经验.

The problem is that sometimes, the inbox accesses mails to my.name@abc.com, sometimes it can be any of the others! I've gone through the Omegahat explanations, but their example is mostly focused on excel, and I have no VB experience.

我想定义从哪个收件箱中检索邮件..到目前为止,我的代码(有不同收件箱的问题).干杯.

I would like to define which inbox to retrieve the mails from.. My code so far (with the problem of varying inboxes). Cheers.

OutApp <- COMCreate("Outlook.Application")
outlookNameSpace = OutApp$GetNameSpace("MAPI")
folder <- outlookNameSpace$Folders(1)$Folders(folderName)
folder$Name(1)
emails <- folder$Items
for (i in 1:10)
{
  subject <- emails(i)$Subject(1)
    print(emails(i)$Subject()) 
}

我正在运行MSOffice Pro Plus 2016

edit: I am running MSOffice Pro Plus 2016

相关:如何使用RDCOMClient从辅助帐户发送Outlook电子邮件-翻译现有的VBA代码?

推荐答案

考虑Outlook的商店对象:

Consider Outlook's Stores Object:

OutApp <- COMCreate("Outlook.Application")
OutStores <- OutApp$Session()$Stores()

# 1ST ACCOUNT
myfolder <- OutStores[[1]]$GetRootFolder()$folders(folderName)

# 2ND ACCOUNT
myfolder <- OutStores[[2]]$GetRootFolder()$folders(folderName)

...

甚至遍历所有商店:

OutApp <- COMCreate("Outlook.Application")
OutStores <- OutApp$Session()$Stores()

store_count <- OutStores$Count()

for (i in 1:store_count) {
    myfolder <- OutStores[[i]]$GetRootFolder()$folders(folderName)

    emails <- myfolder$Items

    for (i in 1:10) {
      subject <- emails(i)$Subject()
      print(subject) 
    }
}

# QUIT APPLICATION
OutApp$Quit()

# RELEASE COM RESOURCES
subject <- NULL; emails <- NULL; myfolder <- NULL
OutStores <- NULL; OutApp <- NULL
gc()

这篇关于R,RDCOMClient和Outlook:使用共享地址访问收件箱消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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