使用Exchange Web服务(EWS)管理API为其他用户创建任务

问题描述:

作为“EWS托管API新手”,我在查找有关创建和管理任务的示例和文档时遇到了一些问题。使用Exchange Web服务(EWS)管理API为其他用户创建任务

我设法为自己创建了一个没有问题的任务。然而,我真的需要能够做到以下几点 - 如果任何人都可以给我任何指针,我真的很感激它...

  1. 创建一个任务,并将其分配给另一个用户。
  2. 能够询问该任务的状态(完成百分比等),同时将其分配给该用户。
  3. 随时更新任务的注释。

预先感谢任何指针!

不幸的是,你不能设置Task.DisplayTo属性。我建议EWS不支持将任务分配给其他人(see post),并且为了获得您需要的功能,您必须在用户的任务文件夹中创建该项目想将其分配到(这是分配,你会从自己的文件夹做不同)

虽然我有这个功能与代理类的工作,我不尚未有它与托管API工作。我假设你可以使用FindFolder方法来检索受让人的任务文件夹,然后在那里创建该项目,但是我会看一看,并在我有一个工作版本时进行更新。

关注此空间;-)

+0

感谢您寻找到这对我来说 - 这是非常非常感谢!我热切地等待着你的回应... – 2010-07-09 10:53:01

我一直在考虑看看这个,我不知道这是可能的使用管理API。

我有一个系统设置使用四个样本用户文件夹,并与委派访问的每个用户的邮箱的中央管理员用户。当我尝试使用API​​查找文件夹时,我只能找到创建服务对象时提供的凭据的用户的文件夹。

我也在使用自动生成的代理对象(只提取了API来尝试和帮助),并且我使用以下过程为另一个用户创建任务(此工作正常...):

  1. 连接到服务器为中心的管理员帐户。
  2. 与您自己的帐户一样创建任务对象。
  3. 创建对要发送项目的用户的任务文件夹的引用。
  4. 创建CreateItemRequest对象传递给服务器,并从步骤2和3的两个项目添加到请求

当发送请求时,该项目被在目标用户的文件夹中创建。

我希望这个序列可能在托管API中,但它似乎不起作用。

我会继续做这个工作,因为我有机会,但我已经与我的工作和约会等问题。我想这个顺序可能会帮助其他人寻找,以防他们有更多的运气。

对不起我不能在此刻

+0

真的很感谢你的帮助 - 我会添加一个Web引用并且自己也玩一下。如果我得到任何地方,会让你知道吗? – 2010-07-09 14:02:49

+0

代码示例转储将很有用...即使不完整(仅包含2,3和4)。 – Seph 2011-11-02 12:19:44

另一种选择是设置使用ExchangeService ImpersonatedUserId属性来冒充谁将会被分配任务的用户提供任何更多的信息。在创建任务之前模拟用户,并且应该在他们的任务文件夹中创建它。

this post的代码为我工作

粘贴代码为后人:

public string CreateTaskItem(string targetMailId) 
    { 

     string itemId = null; 

     task.Subject = "Amit: sample task created from SDE and EWS"; 

     task.Body = new BodyType(); 

     task.Body.BodyType1 = BodyTypeType.Text; 

     task.Body.Value = "Amit created task for you!"; 

     task.StartDate = DateTime.Now; 

     task.StartDateSpecified = true; 



     // Create the request to make a new task item. 

     CreateItemType createItemRequest = new CreateItemType(); 

     createItemRequest.Items = new NonEmptyArrayOfAllItemsType(); 

     createItemRequest.Items.Items = new ItemType[1]; 

     createItemRequest.Items.Items[0] = task; 

     /** code from create appointment **/ 

     DistinguishedFolderIdType defTasksFolder = new DistinguishedFolderIdType(); 

     defTasksFolder.Id = DistinguishedFolderIdNameType.tasks; 
     defTasksFolder.Mailbox = new EmailAddressType(); 

     defTasksFolder.Mailbox.EmailAddress = targetMailId; 

     TargetFolderIdType target = new TargetFolderIdType(); 

     target.Item = defTasksFolder; 



     createItemRequest.SavedItemFolderId = target; 


     try 

     { 

      // Send the request and get the response. 

      CreateItemResponseType createItemResponse = _esb.CreateItem(createItemRequest); 



      // Get the response messages. 

      ResponseMessageType[] rmta = createItemResponse.ResponseMessages.Items; 



      foreach (ResponseMessageType rmt in rmta) 

      { 

       ArrayOfRealItemsType itemArray = ((ItemInfoResponseMessageType)rmt).Items; 

       ItemType[] items = itemArray.Items; 


       // Get the item identifier and change key for each item. 

       foreach (ItemType item in items) 

       { 


//the task id 

        Console.WriteLine("Item identifier: " + item.ItemId.Id); 


//the change key for that task, would be used if you want to track changes ... 
        Console.WriteLine("Item change key: " + item.ItemId.ChangeKey); 

       } 

      } 

     } 

     catch (Exception e) 

     { 

      Console.WriteLine("Error Message: " + e.Message); 

     } 

     return itemId; 

    } 

的Ive最近看到这个,并有以下几点:

我运行,这将建立一个流连接检查邮箱到达新的电子邮件为[email protected]

static void Main(string[] args) 
{ 
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013); 
    WebCredentials wbcred = new WebCredentials("userone", "password", "mydomain"); 
    service.Credentials = wbcred; 

    Console.WriteLine("Attempting to autodiscover Url...");     
    service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback); 

    EWSConnection.SetStreamingNotifications(service); 

    Console.ReadKey(); 
    Environment.Exit(0); 
} 

EWSConnection静态类控制台应用程序的外观松散这样的:

public static void SetStreamingNotifications(ExchangeService service) 
{ 
    _service = service; 

    try 
    {  var subscription = service.SubscribeToStreamingNotifications(
      new FolderId[] { WellKnownFolderName.Inbox }, 
      EventType.NewMail);  

     StreamingSubscriptionConnection connection = new StreamingSubscriptionConnection(service, 5); 

     connection.AddSubscription(subscription); 
     connection.OnNotificationEvent += new StreamingSubscriptionConnection.NotificationEventDelegate(OnEvent); 

     connection.Open(); 

     _subscription = subscription; 
     _subscriptionConnection = connection; 

     Console.WriteLine($"Connection Open:{connection.IsOpen}"); 
    } 

    catch (Exception ex) 
    { 
     Console.WriteLine(ex); 
    } 
} 

有了这个,你可以看到我已经订阅了OnNotificationEvent,而我的OnEvent方法将在新邮件到达时被调用。当新邮件到达此邮箱时,我需要创建一个任务并根据ToAddress属性的内容将其分配给相关人员。

private static void CreateTask(NotificationEvent notification, RecievedMail recievedMail) 
     { 
      try 
      { 
       Console.WriteLine("Attempting to create task"); 

       Microsoft.Exchange.WebServices.Data.Task task = new Microsoft.Exchange.WebServices.Data.Task(_service); 

       task.DueDate = DateTime.Now.AddDays(7); 
       task.Body = recievedMail.Body; 
       task.Subject = recievedMail.Subject; 

       string targetSharedEmailAddress = null; 

       if (recievedMail.ToAddress.ToString() == "humanresources <SMTP:[email protected]>") 
       { 
        targetSharedEmailAddress = "[email protected]";      
       }       

       task.Save(new FolderId(WellKnownFolderName.Tasks,targetSharedEmailAddress)); // 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex); 
      } 
     } 

首先,你可以看到,我尝试添加我想要的任务在task.Save方法要创建的人,但有一次我去的Outlook与新创建的任务互动,车主仍userone,也就是说凭证的人被用来连接到服务,这对我来说是一个问题,因为我需要任务所有者为usertwo

这是通过删除targetSharedEmailAddress变量并改为使用ExchangeServer对象的ImpersonatedUserId属性来完成的。

if (recievedMail.ToAddress.ToString() == "humanresources <SMTP:[email protected]>") 
    { 
     _service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");   
    } 

https://msdn.microsoft.com/en-us/library/office/dd633680(v=exchg.80).aspx