sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户

现象:

  sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户

处理办法:

1.Open the Exchange Management Shell
2.输入: New-ManagementRoleAssignment –Name:impersonationAssignmentName –Role:ApplicationImpersonation –User:administrator 
administrator就是你要设置的模拟账号,当然你也可以设置其他.
Configuring Exchange Impersonation:http://msdn.microsoft.com/en-us/library/bb204095.aspx

获取邮件代码如下:
sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户
 protected void Page_Load(object sender, EventArgs e)
        {
            string OtherUserName = @"jindahao";
            string EWSServiceUrl = "https://po-pek.dentsu.com.cn/EWS/Exchange.asmx";
            string ExchangeAdministrator = "exch-Im";
            string ExchangeAdministratorPassword = "dadayuzhou";
            string DomainName = "dentsu.com.cn";

            ServicePointManager.ServerCertificateValidationCallback = (obj, certificate, chain, errors) => true;
            Microsoft.Exchange.WebServices.Data.ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
            ICredentials creds = new NetworkCredential(ExchangeAdministrator, ExchangeAdministratorPassword, DomainName);
            service.Credentials = new WebCredentials(creds);
            service.Url = (new Uri(EWSServiceUrl));

            service.ImpersonatedUserId = (new ImpersonatedUserId(0, OtherUserName));//模拟账户
            Folder folder = Folder.Bind(service, WellKnownFolderName.Inbox);//Inbox文件夹,不包括子文件夹
            ItemView view = new ItemView(10);
            view.OrderBy.Add(ItemSchema.DateTimeReceived, Microsoft.Exchange.WebServices.Data.SortDirection.Descending);
            foreach (Item item in folder.FindItems(view))
            {
                if (item is EmailMessage)
                {
                    EmailMessage message = item as EmailMessage;

                    string Subject = message.Subject;
                    DateTime ReceiveDate = message.DateTimeReceived;
                    string Sender = message.From.Name;
                    bool HasAttachment = message.HasAttachments;
                }
            }
        }
sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户

金大昊

 

sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户

上一篇:执行计划--在存储过程中使用SET对执行计划的影响


下一篇:拖拽球、三角网格绘制