8

我想通过 Mapi 从 Outllok 导入联系人。标准接触第一步没问题:

MAPIFolder contactObjects = 
outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
foreach (ContactItem contactObject in contactObjects.Items) {
    ... import contact ...
}

在第二步中,我还想导入共享联系人。我发现的唯一一件事是使用

OpenSharedItem(sharedContacts.vcf)

但我不知道要打开的文件(共享项目)的名称。有人知道如何访问共享联系人并可以帮助我吗?

托比


更新:

感谢 vcf 文件的提示。但是我在哪里可以找到它们?


更新2:

我玩过 OutlookSpy。我可以通过共享联系人访问文件夹,但只能通过知道 id(这对于其他用户来说当然不同):

var ns = outlookObj.GetNamespace("MAPI");
var flr = ns.GetFolderFromID("00000000176A90DED92CE6439C1CB89AFE3668F90100D1AD8F66B576B54FB731302D9BB9F6C40007E4BAC5020000");

foreach (var contactObject in flr.Items) {
       ...
}

如何在不知道 ID 的情况下访问文件夹?

4

4 回答 4

2

您将需要显式解析 vCard 文件,或者您可以使用 Redemption - 它允许使用RDOContactItem导入 vCard 文件。Import- http://www.dimastr.com/redemption/RDOMail.htm#methods

于 2012-11-02T17:43:50.433 回答
1

好吧,标题中提出的问题的解决方案几乎很简单。你只需要打电话:

Recipient recip = Application.Session.CreateRecipient("Firstname Lastname");
MAPIFolder sharedContactFolder = Application.Session.GetSharedDefaultFolder(recip, OlDefaultFolders.olFolderContacts);

因为这不能解决我的问题,所以我会问另一个问题

于 2012-11-23T09:40:17.367 回答
0

我已经做了一些编程来获得与 Outlook 的联系。我给你一些示例代码来帮助你解决这个问题..这并不是你想要的,但我认为这会帮助你解决你的问题......

  using System.Collections.Generic; 

// ... 

private List<Outlook.ContactItem> GetListOfContacts(Outlook._Application OutlookApp) 

    { 
    List<Outlook.ContactItem> contItemLst = null; 
    Outlook.Items folderItems =null; 
    Outlook.MAPIFolder mapiFoldSuggestedConts = null; 
    Outlook.NameSpace nameSpc = null; 
    Outlook.MAPIFolder mapiFoldrConts = null; 
    object itemObj = null; 

    try 
    { 

        contItemLst = new List<Outlook.ContactItem>(); 
        nameSpc = OutlookApp.GetNamespace("MAPI"); 
        // getting items from the Contacts folder in Outlook 
        mapiFoldrConts = 
             nameSpc.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); 

        folderItems = mapiFoldrConts.Items; 
        for (int i = 1; folderItems.Count >= i; i++) 
        { 

            itemObj = folderItems[i]; 
            if (itemObj is Outlook.ContactItem) 
                contItemLst.Add(itemObj as Outlook.ContactItem); 
            else 
                Marshal.ReleaseComObject(itemObj); 
        } 

        Marshal.ReleaseComObject(folderItems); 
        folderItems = null; 
        // getting items from the Suggested Contacts folder in Outlook 
        mapiFoldSuggestedConts = nameSpc.GetDefaultFolder( 

             Outlook.OlDefaultFolders.olFolderSuggestedContacts); 

        folderItems = mapiFoldSuggestedConts.Items; 

        for (int i = 1; folderItems.Count >= i; i++) 
        { 

            itemObj = folderItems[i]; 
            if (itemObj is Outlook.ContactItem) 
                contItemLst.Add(itemObj as Outlook.ContactItem); 

            else 
                Marshal.ReleaseComObject(itemObj); 
        } 
    } 

    catch (Exception ex) 
    { 
        System.Windows.Forms.MessageBox.Show(ex.Message); 
    } 

    finally 
    { 

        if (folderItems != null) 
            Marshal.ReleaseComObject(folderItems); 
        if (mapiFoldrConts != null) 
            Marshal.ReleaseComObject(mapiFoldrConts); 
        if (mapiFoldSuggestedConts != null) 
            Marshal.ReleaseComObject(mapiFoldSuggestedConts); 
        if (nameSpc != null) Marshal.ReleaseComObject(nameSpc); 
    } 

    return contItemLst; 

} 
于 2012-11-20T15:43:56.033 回答
0
     var outlook = new Microsoft.Office.Interop.Outlook.Application();
                NameSpace mapiNamespace = outlook.Application.GetNamespace("MAPI");

                foreach (Store store in mapiNamespace.Stores)
                {
                    try
                    {
                        var folder = store.GetRootFolder();

                        foreach(MAPIFolder subfolder in folder.Folders)
                        {
                            if ( subfolder.Name == "Inbox")
                            {
                                foreach(dynamic message in subfolder.Items.Restrict("[MessageClass]='IPM.Sharing'"))
                                {
                                        if (message.Class == 104)//SharingItem
                                        {
                                            Folder sharedFolder = message.OpenSharedFolder();
                                            if (sharedFolder.DefaultMessageClass == "IPM.Contact")
                                            {
                                               //this is your folder
                                            }
                                        }
                                }
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        continue;
                    }
                }
于 2020-04-11T08:43:10.617 回答