ews中如何获取消息entryid

How get message entryid in ews

抱歉英语不好。 我使用 Exchange verson 2010 sp1。 我从 public 文件夹收到消息,我需要从该消息中获取 entryid,例如 Outlook interop:

var service = ConnectToService();
var folder = GetFolder(service, "SomePublicFolder");
var items = folder.FindItems(new ItemView(1));
foreach (EmailMessage item in items)
{
    var entryIdLikeOutlook = ????????
}

我需要这样格式的id:

000000001A447390AA6611CD9BC800AA002FC45A09001207274E1F9F314E9787FCD1B7E58F07000137B94C9100001207274E1F9F314E9787FCD1B7E58F07000137E300B60000

我自己解决了这个问题。 连接到服务示例:

public static class ConnectionToEws
    {
        private static bool RedirectionUrlValidationCallback(string redirectionUrl)
        {
            bool result = false;
            var redirectionUri = new Uri(redirectionUrl);
            if (redirectionUri.Scheme == "https")
            {
                result = true;
            }
            return result;
        }

        public static ExchangeService ConnectToService()
        {
            var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
            {
                Credentials = new WebCredentials("Login", "Password")
                ,UseDefaultCredentials = false
            };
            service.AutodiscoverUrl("EmailAddress", RedirectionUrlValidationCallback);
            return service;
        }
    }

获取 EntryId 示例:

static void Main(string[] args)
        {
            var service = ConnectionToEws.ConnectToService();
            var results = service.FindItems(WellKnownFolderName.Inbox, new ItemView(1));
            foreach (var item in results)
            {
                var originalId = new AlternateId(IdFormat.EwsId, item.Id.ToString(), "EmailAddress", false);
                var entryId = service.ConvertId(originalId, IdFormat.HexEntryId);
                Console.WriteLine(((AlternateId)entryId).UniqueId);
            }
            Console.ReadKey();
        }

public 圩田的变体:

static void Main(string[] args)
        {
            var service = ConnectionToEws.ConnectToService();
            var someFolder = GetFolder(service, "MyFolderName");
            var results = someFolder.FindItems(new ItemView(1));
            foreach (var item in results)
            {
                var alternatePublicFolderItem = new AlternatePublicFolderItemId(IdFormat.EwsId, someFolder.Id.UniqueId, item.Id.ToString());
                var convertResult = service.ConvertId(alternatePublicFolderItem, IdFormat.HexEntryId);
                Console.WriteLine(((AlternatePublicFolderItemId)convertResult).ItemId);
            }

            Console.ReadKey();
        }

        private static Folder GetFolder(ExchangeService service, string folderName)
        {
            var folderView = new FolderView(int.MaxValue);
            var findFolderResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, folderView);
            foreach (var folder in findFolderResults)
            {
                if (folderName.Equals(folder.DisplayName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return folder;
                }
            }
            return null;
        }