读取Exchange的用户未读邮件数的几种方法
【http://www.cnblogs.com/nbpowerboy/p/3539422.html】
可以使用ExchangeServiceBinding获取邮件,他相当于outlook, 来获取服务器的未接受的邮件.
至于 “该帐户无权模拟所请求的用户 ” ,是由于在exchange服务器上面没有配置模拟账户.
需要在Exchange Management Shell上执行: New-ManagementRoleAssignment –Name:impersonationAssignmentName –Role:ApplicationImpersonation –User:administrator
见: Configuring Exchange Impersonation:http://msdn.microsoft.com/en-us/library/bb204095.aspx
设置后, 就不会有该帐户无权模拟所请求的用户问题了。
public static int GetUnReadMailCountByUserMailAddress(string UserMailAddress) { int unRead = 0; string url = "https://{0}/ews/exchange.asmx"; url = string.Format(url, m_ExchangeMachine); try { ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1); service.Credentials = new NetworkCredential(m_ServerUser, m_Password, m_Domain); service.Url = new Uri(url); service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, UserMailAddress); unRead = Folder.Bind(service,WellKnownFolderName.Inbox).UnreadCount; } catch (Exception ex) { return unRead; throw; } return unRead; }
因为向往 所以选择了远方
因为无可依靠 所以必须坚强