使用Exchange Web服务API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Exchange Web服务API相关的知识,希望对你有一定的参考价值。

In order for the code snippet(s) to work, you need to do the following:

1. Go download the EWS API SDK: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=c3342fb3-fbcc-4127-becf-872c746840e1
2. Install the SDK on your machine. It will install a .dll .xml and walkthrough guide to C:Program FilesMicrosoftExchange...
3. Open up your VS project solution and add a reference to the installed DLL

It's important to note that you should use the service.AutodiscoverUrl instead of service.Url because the URL you use may not be the correct URL down the line (due to redirection). If you are using service.Url and you call a method and get a 405 error, switch to the AutodiscoverUrl method instead.
  1. //add the following required namespaces:
  2. using Microsoft.Exchange.WebServices.Data;
  3. using System.Net.Security;
  4. using System.Security.Cryptography.X509Certificates;
  5.  
  6. //create a callback required for the AutodiscoverUrl method:
  7. private static bool ValidateRedirectionUrlCallback(string url)
  8. {
  9. //Validate the URL and return true to allow the redirection
  10. return true;
  11. }
  12.  
  13. private ExchangeService(string EmailAddress)
  14. {
  15. ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
  16. service.Credentials = new NetworkCredential("<username>","<password>","<domain>");
  17. service.AutodiscoverUrl(EmailAddress, ValidateRedirectionUrlCallback);
  18. return service;
  19. }
  20.  
  21. //example of using this service to set an appointment
  22. public void SetAppointment()
  23. {
  24. ExchangeService service = ExchangeService("<email service>");
  25. Appointment appt = new Appointment(service);
  26. appt.Subject = "<subject>";
  27. appt.Body = "<body>";
  28. appt.Start = DateTime.Now;
  29. appt.End = DateTime.Now.AddHours(2);
  30. appt.Save(WellKnownFolderName.Calendar);
  31. }

以上是关于使用Exchange Web服务API的主要内容,如果未能解决你的问题,请参考以下文章

Exchange Web 服务通知

Exchange Web 服务 - 如何使用 Account 扩展属性检索联系人

用于不知名文件夹名称的 Exchange Web 服务 FolderId

如何使用 Exchange Web 服务为其他用户查找日历项目

使用服务帐户的 C# 和 Exchange Web 服务 - 错误

如何使用 EWS Java API (Exchange Web Service) 设置联系人标题?