在给定entryid(或storeid)的情况下,是否有方法获取mapifolder或outlook interop文件夹的smtpaddress

在给定entryid(或storeid)的情况下,是否有方法获取mapifolder或outlook interop文件夹的smtpaddress,outlook,Outlook,如果我有通过outlook interop库中的folderpicker选择的mapifolder的storeid,是否有方法获取该文件夹的smtpaddress 我知道它在扩展属性中,但我希望在不进行任何繁重的解析或ldap查询的情况下完成它 我需要smtpaddress的原因是为了通过EWS连接到文件夹-我目前正试图用exchange web服务替换对outlook interop的引用,这已成为一个症结所在,因为我们的许多用户都可以为邮箱所有者委派对不属于他们的邮箱的访问权限,您可以尝试读

如果我有通过outlook interop库中的folderpicker选择的mapifolder的storeid,是否有方法获取该文件夹的smtpaddress

我知道它在扩展属性中,但我希望在不进行任何繁重的解析或ldap查询的情况下完成它


我需要smtpaddress的原因是为了通过EWS连接到文件夹-我目前正试图用exchange web服务替换对outlook interop的引用,这已成为一个症结所在,因为我们的许多用户都可以为邮箱所有者委派对不属于他们的邮箱的访问权限,您可以尝试读取MAPIFolder.Store属性以访问父存储,然后读取PR\u MAILBOX\u OWNER\u ENTRYID属性(DASL name
)http://schemas.microsoft.com/mapi/proptag/0x661B0102“
)使用Store.PropertyAccessor.GetProperty。然后可以使用存储所有者条目id调用Namespace.GetAddressEntryFromID。拥有AddressEntry对象后,可以使用AddressEntry.GetExchangeUser.PrimarySmtpAddress

请注意,PR_MAILBOX_OWNER_ENTRYID属性仅在在线商店中可用。您可能希望使用及其.Owner.SmtpAddress属性。RDOExchangeMailboxStore可以使用RDOSession.GetRDOObjectfromOutlookObject(Store)或使用RDOSession.GetStoreFromID检索。

我知道已经过了几年(对不起),但我需要获取大量邮箱的SMTP地址,而接受的答案不起作用(因为我有脱机存储),所以我进行了解析

publicstaticbooltrygetsmtpaddress(MAPIFolder文件夹,输出字符串smtpAddress)
{
smtpAddress=默认值;
var storeId=HexToBytes(folder.storeId);
//检查它是否是商店入口id
if(位转换器.ToUInt64(存储ID,4)!=0x1A10E50510BBA138UL
||BitConverter.ToUInt64(存储ID,12)!=0xC2562A2B00008BBA1UL){返回false;}
var indexDn=Array.IndexOf(storeId,(字节)0x00,60)+1;
var indexV3Block=Array.IndexOf(storeId,(字节)0x00,indexDn)+1;
//检查是否为V3条目id(带SMTP地址)
if(BitConverter.ToUInt32(storeId,indexV3Block)!=0xF43246E9UL){return false;}
var offsetSmtpAddress=BitConverter.ToUInt32(storeId,indexV3Block+12);
smtpAddress=BytesToUnicode(存储ID,indexV3Block+(int)偏移量smtpAddress);
返回true;
}
专用静态字节[]十六进制字节(字符串输入)
{
var bytesLength=input.Length/2;
var bytes=新字节[bytesLength];
对于(vari=0;i
NZTony在VB.net中的回答:

Public Sub test()
        Dim smtpAddress As String
        Dim selectedItem As Outlook.Folder
        smtpAddress = ""
        TryGetSmtpAddress(Application.ActiveExplorer.Selection.Item(1).Parent, smtpAddress)
End Sub

Public Shared Function TryGetSmtpAddress(ByVal folder As MAPIFolder, ByRef smtpAddress As String) As Boolean
        smtpAddress = "default"
        Dim storeId = HexToBytes(folder.StoreID)

        If BitConverter.ToUInt64(storeId, 4) <> &H1A10E50510BBA138UL OrElse BitConverter.ToUInt64(storeId, 12) <> &HC2562A2B0008BBA1UL Then
            Return False
        End If

        Dim indexDn = Array.IndexOf(storeId, CByte(&H0), 60) + 1
        Dim indexV3Block = Array.IndexOf(storeId, CByte(&H0), indexDn) + 1

        If BitConverter.ToUInt32(storeId, indexV3Block) <> &HF43246E9UL Then
            Return False
        End If

        Dim offsetSmtpAddress = BitConverter.ToUInt32(storeId, indexV3Block + 12)
        smtpAddress = BytesToUnicode(storeId, indexV3Block + CInt(offsetSmtpAddress))
        Return True
End Function

    Private Shared Function HexToBytes(ByVal input As String) As Byte()
        Dim bytesLength = input.Length / 2
        Dim bytes = New Byte(bytesLength - 1) {}

        For i = 0 To bytesLength - 1
            bytes(i) = Convert.ToByte(input.Substring(i * 2, 2), 16)
        Next

        Return bytes
End Function

    Private Shared Function BytesToUnicode(ByVal value As Byte(), ByVal startIndex As Integer) As String
        Dim charsLength = (value.Length - startIndex) / 2
        Dim chars = New Char(charsLength - 1) {}

        For i = 0 To charsLength - 1
            Dim c = CSharpImpl.__Assign(chars(i), BitConverter.ToChar(value, startIndex + i * 2))
            If c = vbNullChar Then
                Return New String(chars, 0, i)
            End If
        Next

        Return New String(chars)
End Function

Private Class CSharpImpl
        <Obsolete("Please refactor calling code to use normal Visual Basic assignment")>
        Shared Function __Assign(Of T)(ByRef target As T, value As T) As T
            target = value
            Return value
        End Function
End Class

公共子测试()
作为字符串的Dim smtpAddress
Dim selectedItem作为Outlook.Folder
smtpAddress=“”
TryGetSmtpAddress(Application.ActiveExplorer.Selection.Item(1).父项,smtpAddress)
端接头
作为布尔值的公共共享函数TryGetsMTAddress(ByVal文件夹作为MAPIFolder,ByRef smtpAddress作为String)
smtpAddress=“默认”
Dim storeId=HexToBytes(folder.storeId)
如果BitConverter.ToUInt64(storeId,4)和H1A10E50510BBA138UL或LSE BitConverter.ToUInt64(storeId,12)和HC2562A2B0008BBA1UL,则
返回错误
如果结束
Dim indexDn=Array.IndexOf(storeId,CByte(&H0),60)+1
Dim indexV3Block=Array.IndexOf(存储ID、CByte(&H0)、indexDn)+1
如果BitConverter.ToUInt32(存储ID、indexV3Block)和HF43246E9UL,则
返回错误
如果结束
Dim offsetSmtpAddress=位转换器.ToUInt32(存储ID,索引XV3BLOCK+12)
smtpAddress=BytesToUnicode(存储ID,索引XV3Block+CInt(偏移smtpAddress))
返回真值
端函数
私有共享函数HexToBytes(ByVal输入为字符串)为Byte()
Dim字节长度=输入长度/2
Dim字节=新字节(字节长度-1){
对于i=0到字节长度-1
字节(i)=转换.ToByte(输入.Substring(i*2,2),16)
下一个
返回字节
端函数
私有共享函数BytesToUnicode(ByVal值为Byte(),ByVal startIndex为整数)作为字符串
Dim charsLength=(value.Length-startIndex)/2
Dim chars=新字符(字符长度-1){
对于i=0到charsLength-1
Dim c=csharpumpl.\uu赋值(字符(i),位转换器.ToChar(值,startIndex+i*2))
如果c=vbNullChar,则
返回新字符串(字符,0,i)
如果结束
下一个
返回新字符串(字符)
端函数
私有类CSharpImpl
共享函数uu分配(Of T)(ByRef目标为T,值为T)为T
目标=价值
返回值
端函数
末级

通常,文件夹没有SMTP地址。你是指文件夹id吗?我不是指文件夹所在邮箱所有者的smtpaddress。为了获取mapifolder的entryid属性并将其转换为exchange web服务存储id,我需要提供邮箱所有者的smtpaddress。是idformat的枚举。因此,我想在达到上一条评论的编辑限制时进行转换,但当我使用folderpicker在另一个用户的邮箱(我有权访问)中选择文件夹时,我得不到任何关于Account的信息这就像一个符咒一样工作-id添加的唯一一件事是GetProperty返回一个字节(),并且使用system.text.encoding将其转换为字符串无法按预期工作。相反,您需要使用PropertyAc