gpt4 book ai didi

outlook - 有没有办法在给定 entryid(或 storeid)的情况下获取 mapifolder 或 outlook interop 文件夹的 smtpaddress

转载 作者:行者123 更新时间:2023-12-02 15:33:49 24 4
gpt4 key购买 nike

如果我有一个 mapifolder 的 storeid,通过文件夹选择器从 outlook interop 库中选择,我有没有办法获得该文件夹的 smtpaddress?

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

我需要 smtpaddress 的原因是为了通过 EWS 连接到文件夹 - 我目前正在尝试用 exchange web 服务替换我们对 outlook interop 的引用,这已成为一个症结所在,因为我们的许多用户对不属于他们的邮箱有代理访问权限

最佳答案

我知道这是几年后的事了(抱歉),但我需要为一堆邮箱获取 SMTP 地址,而接受的答案不起作用(因为我有离线商店)所以我进行了解析。

public static bool TryGetSmtpAddress(MAPIFolder folder, out string smtpAddress)
{
smtpAddress = default;

var storeId = HexToBytes(folder.StoreID);

// check it's a store entry id
if (BitConverter.ToUInt64(storeId, 4) != 0x1A10E50510BBA138UL
|| BitConverter.ToUInt64(storeId, 12) != 0xC2562A2B0008BBA1UL) { return false; }

var indexDn = Array.IndexOf(storeId, (byte)0x00, 60) + 1;
var indexV3Block = Array.IndexOf(storeId, (byte)0x00, indexDn) + 1;

// check it's a V3 entry id (with SMTP address)
if (BitConverter.ToUInt32(storeId, indexV3Block) != 0xF43246E9UL) { return false; }

var offsetSmtpAddress = BitConverter.ToUInt32(storeId, indexV3Block + 12);

smtpAddress = BytesToUnicode(storeId, indexV3Block + (int)offsetSmtpAddress);
return true;
}

private static byte[] HexToBytes(string input)
{
var bytesLength = input.Length / 2;
var bytes = new byte[bytesLength];
for (var i = 0; i < bytesLength; i++) { bytes[i] = Convert.ToByte(input.Substring(i * 2, 2), 16); }
return bytes;
}

private static string BytesToUnicode(byte[] value, int startIndex)
{
var charsLength = (value.Length - startIndex) / 2;
var chars = new char[charsLength];
for (var i = 0; i < charsLength; i++)
{
var c = chars[i] = BitConverter.ToChar(value, startIndex + i * 2);
if (c == '\0') { return new String(chars, 0, i); }
}
return new String(chars);
}

关于outlook - 有没有办法在给定 entryid(或 storeid)的情况下获取 mapifolder 或 outlook interop 文件夹的 smtpaddress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21443597/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com