簡體   English   中英

如何在ews中獲取消息entryid

[英]How get message entryid in ews

對不起,英語不好。 我使用Exchange版本2010 SP1。 我從公用文件夾獲取消息,我需要從此消息中獲取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();
        }

因公共田而異:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM