使用Microsoft.Office.Interop.Outlook访问其他Exchange邮箱

时间:2010-08-12 13:05:56

标签: interop outlook exchange-server

我正在尝试使用Office.Interop.Outlook COM对象找到一种方法来连接到其他邮箱。目前我正在执行以下操作(添加COM对象后):

var app = new Microsoft.Office.Interop.Outlook.Application();
var ns = app.GetNamespace("MAPI");
ns.Logon();
var inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

这成功地将我连接到我的主要收件箱,然后我可以循环播放。

我接下来要找的是一种使用其他邮箱X并获取默认文件夹的方法。

我正在使用Framework 4.0和COM对象Microsoft Outlook 12.0对象库(版本9.3)

在Exchange版本上不确定。

干杯

2 个答案:

答案 0 :(得分:3)

我想我拥有它: -

ns = app.GetNamespace("MAPI");
ns.Logon();
var recipient = ns.CreateRecipient("xx@yy.com");
recipient.Resolve();
var sharedFolder = ns.GetSharedDefaultFolder(recipient, Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

不确定ns.Logon是否有必要,但我还是离开了。

答案 1 :(得分:1)

卢克上面有正确的答案。以下代码适用于使用pywin32的Python 3.7:

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

other_user = outlook.CreateRecipient("user.name@example.com")
print(other_user)
other_mailbox = outlook.GetSharedDefaultFolder(other_user, 6) # 6= inbox see https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.outlook.oldefaultfolders?view=outlook-pia
print(other_mailbox)
print(other_mailbox.Items[0])