开发者

Get Inboxes from Outlook

开发者 https://www.devze.com 2023-03-23 21:02 出处:网络
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 re开发者_StackOverflow中文版turn the first one.

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 re开发者_StackOverflow中文版turn 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).


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.


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


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 (I am its author) - RDOStore.GetDefaultFolder.


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


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

精彩评论

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