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获取邮件代码如下:
 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(, OtherUserName));//模拟账户
Folder folder = Folder.Bind(service, WellKnownFolderName.Inbox);//Inbox文件夹,不包括子文件夹
ItemView view = new ItemView();
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;
}
}
}

金大昊

上一篇:北斗导航 | 获取观测卫星的位置信息,并绘制卫星的方位角和仰角得到星空图:GSV语句(附Matlab源代码)


下一篇:CORS跨域