使用EWS访问邮箱 [英] Access Mail Box using EWS

查看:224
本文介绍了使用EWS访问邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Exchange Web服务来访问邮箱内容.Exchange Web服务URL
https://pod51007.outlook.com/EWS/Exchange.asmx 。但是从我的代码中访问URL会引发401:未经授权访问错误。

I'm trying to use Exchange Web Services to access mailbox content.The Exchange Web Service URL is https://pod51007.outlook.com/EWS/Exchange.asmx.But accessing the URL from my code throws 401:Unauthorized Access Error.

代码段:

Code Snippet:

ExchangeServiceBinding binding = new ExchangeServiceBinding();

            binding.Credentials = new NetworkCredential( windowsliveid
密码);

             binding.Url =" https://pod51007.outlook.com/EWS/Exchange.asmx" ;;

            FindItemType request = new FindItemType();

            request.ItemShape = new ItemResponseShapeType();

            request.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;

            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();

            folder.Id = DistinguishedFolderIdNameType.inbox;

            folder.Mailbox = new EmailAddressType();

            folder.Mailbox.EmailAddress = windowsLiveUserId;

            request.ParentFolderIds = new BaseFolderIdType [] {folder};

            request.Traversal = ItemQueryTraversalType.Shallow;

            ItemType [] messages = null;

           试试
            {

                FindItemResponseType response = binding.FindItem(request);

                FindItemResponseMessageType responseMessage =

                response.ResponseMessages.Items [0] as FindItemResponseMessageType;

                if(responseMessage.ResponseClass!= ResponseClassType.Success)

                {



                }
                messages =(responseMessage.RootFolder.Item as ArrayOfRealItemsType).Items;

            }
            catch(例外情况)

            {

               抛出新的例外(ex.Message);

            }

ExchangeServiceBinding binding = new ExchangeServiceBinding();
            binding.Credentials = new NetworkCredential(windowsliveid, password);
            binding.Url = "https://pod51007.outlook.com/EWS/Exchange.asmx";
            FindItemType request = new FindItemType();
            request.ItemShape = new ItemResponseShapeType();
            request.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
            DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
            folder.Id = DistinguishedFolderIdNameType.inbox;
            folder.Mailbox = new EmailAddressType();
            folder.Mailbox.EmailAddress = windowsLiveUserId;
            request.ParentFolderIds = new BaseFolderIdType[] { folder };
            request.Traversal = ItemQueryTraversalType.Shallow;
            ItemType[] messages = null;
            try
            {
                FindItemResponseType response = binding.FindItem(request);
                FindItemResponseMessageType responseMessage =
                response.ResponseMessages.Items[0] as FindItemResponseMessageType;
                if (responseMessage.ResponseClass != ResponseClassType.Success)
                {

                }
                messages = (responseMessage.RootFolder.Item as ArrayOfRealItemsType).Items;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

 

以上代码抛出401 - 我的asp.net解决方案出错。请让我知道这个问题。

The above code throws 401 - Error in my asp.net solution.Please let me know about this issue.

推荐答案

您好,

因为我了解您的代码,您尝试使用委托访问邮箱。您是否已授权"windowsLiveUserId"访问权限?帐户 ?

as I understand your code, you try to access a mailbox using delegation. Have you delegate access on "windowsLiveUserId" account ?

问候,


这篇关于使用EWS访问邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆