开发者

Access Additional Exchange Mailbox using Microsoft.Office.Interop.Outlook

开发者 https://www.devze.com 2023-01-11 12:16 出处:网络
I\'m tryingto find a way using the Office.Interop.Outlook COM object to connect to an additional Mailbox.Currently I am doing the following (after adding the COM object):

I'm trying to find a way using the Office.Interop.Outlook COM object to connect to an additional Mailbox. Currently I am doing the following (after adding the COM object):

var app = new Microsoft.Office.Interop.Outlook.Application();
var ns = app.GetNamespace("MAPI");
ns.Logo开发者_如何学Cn();
var inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

This successfully connects me to my main Inbox which I can then loop through.

What I am trying to find next is a way to use additional Mailbox X and get the default folder.

I am using Framework 4.0 with the COM object Microsoft Outlook 12.0 Object Library (version 9.3)

Not sure on the version of Exchange.

Cheers


I think I have it :-

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);

Not sure if the ns.Logon is necessary, but I have left it anyway.


Luke has the correct answer above. The following code works for Python 3.7 using pywin32:

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://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.outlook.oldefaultfolders?view=outlook-pia
print(other_mailbox)
print(other_mailbox.Items[0])
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号