Get Inboxes from Outlook

2019-04-30 01:55发布

I configured two Exchange accounts in Outlook 2010, however I cant find out how to get to Inbox of the second account. Session.GetDefaultFolder() always return the first one.

Even enumerating Session.Accounts, finding the right account and calling Session.Account(found one).Store.GetDefaultFolder() returns wrong Inbox (from the default exchange account, not the secondary).

5条回答
Luminary・发光体
2楼-- · 2019-04-30 02:25

Does this show you all the available Inboxes?

Sub LoopThroughInboxes

Dim ol As Outlook.Application
Dim ns As Outlook.NameSpace
Dim i As Long

Set ol = Outlook.Application
Set ns = ol.GetNamespace("MAPI")

For i = 1 To ns.Folders.Count
 Debug.Print ns.Folders(i).Name
Next i

If so then ns.Folders(i).Folders("Inbox") will get you the Inbox for each mailbox.

查看更多
祖国的老花朵
3楼-- · 2019-04-30 02:26

I guess this is an old one, but somebody might need it one day. Here is code to iterate all "Sent Mail" folders in Outlook. (I think this will only work for Outlook 2010 and newer).

MSOutlook._NameSpace ns = Globals.ThisAddIn.Application.GetNamespace("MAPI");
var accounts = ns.Accounts;
foreach (MSOutlook.Account account in accounts)
{
    try
    {
        // You might want to test if DeliveryStore is null, in case this account is not an Exchange account
        MSOutlook.MAPIFolder sentFolder = account.DeliveryStore.GetDefaultFolder(MSOutlook.OlDefaultFolders.olFolderSentMail);
        if(sentFolder != null)
        {
            SentItems = sentFolder.Items;
            SentItems.ItemAdd += LogMethods.Items_Sent_ItemAdd;
        }
    }
    catch (Exception e)
    {
        BaseClass.log.Log(LoggLevel.Warning, e.Message);
    }
}
查看更多
疯言疯语
4楼-- · 2019-04-30 02:31

Use Store.GetDefaultFolder instead of Namespace.GetDefaultFolder. Note that Store.GetDefaultFolder was added in Outlook 2010. In the earlier versions of Outlook use Extended MAPI (C++ or Delphi) or Redemption (RDOStore.GetDefaultFolder.

查看更多
我命由我不由天
5楼-- · 2019-04-30 02:32

Maybe you have long given up on this question, but here goes...

I've had this same problem before and I solved it by adding the Outlook Account Management API. Unfortunately for you, this a c++ oriented API. (My addin was already developed in c++)

Furthermore, the OOM (Outlook Object Model) which VBA and the .NET addins use has poor (if any) support for multiple accounts. By adding to exchange accounts, you have essentially added multiple accounts to your profile.

So, You might have to go down a level, using MAPI with c++ and then hook in the Outlook Account Management API. It's a lot of work, but that's exactely what I did and it worked like a charm.

Also, here is an example: http://www.codeproject.com/KB/IP/IOlkAccountManager.aspx

查看更多
萌系小妹纸
6楼-- · 2019-04-30 02:35

To Go to Mapix library

Mapix library link as given below

Mapix library for C++/MFC

Note: This Library valid for Inbox emails in MS Outlook

查看更多
登录 后发表回答