Outlook Mapi 访问共享联系人

问题描述 投票:0回答:5

我想通过 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 的情况下访问该文件夹?

c# outlook shared mapi
5个回答
2
投票

您需要显式解析 vCard 文件,或者可以使用 Redemption(我是其作者) - 它允许使用 RDOContactItem.

Import
导入 vCard 文件 - http://www.dimastr.com/redemption /RDOMail.htm#methods


1
投票

标题中提出的问题的解决方案几乎很简单。 您只需拨打:

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

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


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; 

} 

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

0
投票

我分享一个从outlook获取文件的方法

子移动器CorreoALM()

Dim outlookApp As Object
Dim namespace As Object
Dim inbox As Object
Dim items As Object
Dim item As Object
Dim attachment As Object
Dim saveFolder As String

' Ruta de la carpeta de destino
saveFolder = "C:\MiCarpeta\"

' Inicializar Outlook
Set outlookApp = CreateObject("Outlook.Application")
Set namespace = outlookApp.GetNamespace("MAPI")
Set inbox = namespace.GetDefaultFolder(6) ' Carpeta de entrada

' Filtrar correos con asunto que contiene "ALM" y un solo archivo adjunto Excel que comienza con "Estatus "
Set items = inbox.Items.Restrict("[Subject] Like '%ALM%' AND [Attachments.Count] = 1 AND [Attachments.Item(1).FileName] Like 'Estatus *.xls*'", True)

' Buscar el último correo (más reciente)
items.Sort "[ReceivedTime]", False

' Procesar el correo más reciente que cumple con los criterios
If items.Count > 0 Then
    Set item = items(1) ' Tomar el correo más reciente

    ' Guardar el archivo adjunto en la carpeta de destino
    Set attachment = item.Attachments(1)
    attachment.SaveAsFile saveFolder & attachment.FileName

    ' Mover el correo a la carpeta "CarpetaALM"
    item.Move namespace.GetDefaultFolder(6).Folders("CarpetaALM")
Else
    MsgBox "No se encontraron correos que cumplan con los criterios.", vbInformation
End If

' Limpiar objetos
Set outlookApp = Nothing
Set namespace = Nothing
Set inbox = Nothing
Set items = Nothing
Set item = Nothing
Set attachment = Nothing

结束子

© www.soinside.com 2019 - 2024. All rights reserved.