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

发布于 2024-09-08 17:26:20 字数 250 浏览 3 评论 0原文

作为“EWS 托管 API 新手”,我在查找有关创建和管理任务的示例和文档时遇到了一些问题。

我已经成功地为自己创建了一个任务,没有出现任何问题。但是,我确实需要能够执行以下操作 - 如果有人能给我任何指示,我将非常感激......

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

预先感谢您的任何指点!

As an "EWS Managed API Newbie", I'm having some problems finding examples and documentation about creating and managing Tasks.

I've managed to create a task for myself without a problem. However, I really need to be able to do the following - if anyone could give me any pointers I'd really appreciate it...

  1. Create a Task and assign it to another user.
  2. Be able to interrogate the status of that task (percent complete, etc) whilst it is assigned to that user.
  3. Update the notes on the task at any time.

Thanks in advance for any pointers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

拥抱影子 2024-09-15 17:26:20

这篇文章中的代码为我工作

为后代粘贴代码:

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;

    }

The code in this post worked for me

Pasting code for posterity:

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;

    }
摘星┃星的人 2024-09-15 17:26:20

我一直在研究这个问题,但不确定是否可以使用托管 API。

我使用四个示例用户文件夹设置了一个系统,以及一个中央管理用户,该用户具有对每个用户邮箱的委派访问权限。当我尝试使用 API 查找文件夹时,我只能找到创建服务对象时提供的凭据的用户的文件夹。

我还使用自动生成的代理对象(仅选择 API 来尝试提供帮助),并且我使用以下过程为另一个用户创建任务(这可以正常工作...)

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

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

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

一旦有机会,我会继续努力,但我也有其他关于我正在处理的约会问题。我认为这个序列可能会帮助其他人寻找,如果他们有更多的运气的话。

抱歉,我目前无法提供更多信息

I've been taking a look into this, and i'm not sure it's possible using the Managed API.

I've got a system set up using four sample user folders, and a central admin user with delegated access to each of those user's mailboxes. When i attempt to find folders using the API, i can only find the folders of the user who's credentials i supply when creating the service object.

I'm also using the auto-generated proxy objects (only picked up the API to try and help), and I use the following process to create a task for another user (this works correctly...):

  1. Connect to the server as the central admin account.
  2. Create the task object as you would for your own account.
  3. Create a reference to the Tasks folder of the user that you want to send the item to.
  4. Create a CreateItemRequest object to pass to the server, and add the two items from steps 2 and 3 to the request

When the request is sent, the item is created in the target user's folder.

I was hoping that this sequence might be possible in the managed API, but it doesnt seem to work.

I'll keep working on it as i get the chance, but i have other issues with appointments that i'm working on as well. I figured the sequence might help anyone else looking, in case they have more luck.

Sorry i cant provide any more info at the moment

渡你暖光 2024-09-15 17:26:20

另一个选项是使用 ExchangeService ImpersonatedUserId 属性来模拟将被分配任务的用户。在创建任务之前模拟用户,并且应在其任务文件夹中创建该任务。

Another option is set use the ExchangeService ImpersonatedUserId property to impersonate the user who will be assigned the Task. Impersonate the user before creating the task and it should be created in their Tasks folder.

橘寄 2024-09-15 17:26:20

不幸的是,您无法设置 Task.DisplayTo 属性。我建议 EWS 仍然不支持将任务分配给其他人(请参阅帖子),并且为了获得您所需的功能,您必须在所需用户的任务文件夹中创建该项目将其分配给(这与分配不同,您可以在自己的文件夹中进行分配)

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

注意这个空间;-)

Unfortunately, you cant set the Task.DisplayTo property. I would suggest that it's still the case that EWS doesn't support assigning tasks to others (see post) and that, in order to get the functionality you require, you'd have to create the item in the Tasks folder of the user that you want to assign it to (this is different to assigning, which you would do from your own folder)

While i have this functionality working with the proxy classes, i dont yet have it working with the managed API. I would assume that you can use the FindFolder method to retrieve the assignee's tasks folder, and then create the item there, but i'll have a look, and update when i have a working version.

Watch this space ;-)

2024-09-15 17:26:20

我最近一直在研究这个问题,并有以下内容:

我正在运行一个控制台应用程序,它将设置一个流连接来检查 [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

Ive been looking into this more recently and have the following:

I am running a Console application which will set up a streaming connection to check for new emails arriving in the mailbox for [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);
}

My EWSConnection static class looks loosely like this:

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);
    }
}

With this, you can see I have subscribed to the OnNotificationEvent and in turn my OnEvent method will be invoked when a new email arrives. When a new email arrives to this mailbox I have a requirement to create a task and assign it to the relevant person, based on what the ToAddress property is.

  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);
            }
        }

At first you can see that I tried adding the person that I wanted the task to be created for in the task.Save method, however once I went to Outlook to interact with the newly created task, the owner was still userone, i.e. the person who's credentials were used to connect to the service, this was an issue for me as I need the task owner to be usertwo.

This was accomplished by dropping the targetSharedEmailAddress variable and instead using the ImpersonatedUserId property of the ExchangeServer object.

 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文