移动后如何继续使用EmailMessage [英] How do I keep working with an EmailMessage after I move it

查看:119
本文介绍了移动后如何继续使用EmailMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将应用程序从WebDav移植到EWS托管API。该应用程序在交换服务器上的多个收件箱中查找电子邮件并对其进行处理。


在一个场景中,我需要保留电子邮件并等待相关的电子邮件到达我之前可以处理它们。我将电子邮件移动到"待定"状态。正在等待相关联的电子邮件到达时的文件夹。


将电子邮件移动到"待定"电子邮件是很容易的。使用API​​的文件夹,但是一旦我移动它,ID就会发生变化,而且我的EmailMessage对象不再与服务器上的消息有关。


我想知道如何移动从收件箱到另一个文件夹的电子邮件,仍然能够保留对邮件的引用,以便我可以使用它。


以下是示例代码:

 Dim MyMailBox As New Mailbox(" test@mydomain.com")
Dim InboxFolderID As New FolderId(WellKnownFolderName.Inbox,MyMailBox)
Dim MessageList As FindItemsResults( Of Item)= m_Service.FindItems(InboxFolderID,New ItemView(1))
Dim msg As Item = MessageList.Items(0)
msg.Move(PendingFolderID)'这会移动消息
msg.Move(CompletedFolderID)'这会返回一个异常在商店中找不到指定的对象

我知道当你在Exchange中移动一个项目时它会在内部复制一个副本然后删除,以便移动的项目实际上是一个新项目。当我第一次使用WebDav构建这个程序时,这一直是我必须解决的问题。那时我只是将
重命名为电子邮件的URI以包含一个GUID,我可以用它来再次找到该电子邮件。


我认为答案是来自的返回值move方法,它是一个EmailMessage对象。我认为它必须是新创建的消息。不幸的是,看起来它只是在移动之前返回消息,这是没有用的,因为它已经从服务器中删除了


我已经阅读了一些建议的帖子我需要通过搜索PR_SEARCH_KEY来查找移动的消息。这看起来像一个复杂的方法,我很困惑,没有一个更简单的方法来做一个简单的要求。


任何建议都将不胜感激。

解决方案

从Exchange 2007 SP2起,EWS返回邮箱中已移动邮件的ID。使用EWS Managed API,您只需要编写:

 Item movedItem = myItem.Move(destinationFolder); 


有三个限制:复制跨邮箱或从公用文件夹复制或仍然不会返回Id。如果要在这些情况下检索项目的移动副本,我们建议您在移动项目之前使用自定义扩展属性进行标记,然后使用
然后使用目标文件夹中的FindItems查找已移动的副本。


I am trying to port an application from WebDav to EWS Managed API. The application looks for emails in a number of inboxes on an exchange server and processes them.

In one scenario I need to hold on to the email and wait for an associated email to arrive before I can process them both. I move the email into a “pending” folder while it is waiting for the associated email to arrive.

It is easy to move the email to the “pending” folder using the API, but once I have moved it the ID changes and my EmailMessage object does not relate to the message on the server any more.

I would like to know how I can move an email from the inbox to another folder and still be able to keep a reference to the message so I can work with it.

Here is sample code:

Dim MyMailBox As New Mailbox("test@mydomain.com")
Dim InboxFolderID As New FolderId(WellKnownFolderName.Inbox, MyMailBox)
Dim MessageList As FindItemsResults(Of Item) = m_Service.FindItems(InboxFolderID, New ItemView(1))
Dim msg As Item = MessageList.Items(0)
msg.Move(PendingFolderID) ' this moves the message
msg.Move(CompletedFolderID) ' this returns an exception The specified object was not found in the store

I know that when you move an item in Exchange it internally does a copy then a delete so the moved item is effectively a new item. This has always been a problem which I had to work around when I first built this program using WebDav. Back then I just renamed the URI of the email to include a GUID which I could use to locate the email again.

I thought the answer was in the return value from the move method which is an EmailMessage object. I figured it must be the newly created message. Unfortunately, it looks like it just returns the Message before it was moved which is of no use since it has been deleted from the server.

I have read some posts that suggest I need to go looking for the moved message by searching for the PR_SEARCH_KEY. That looks like a complicated approach and I’m puzzled that there is not an easier way to do what should be a simple requirement.

Any suggestions would be greatly appreciated.

解决方案

As of Exchange 2007 SP2, EWS returns the Id of moved messages within a mailbox. With the EWS Managed API, you just need to write:

Item movedItem = myItem.Move(destinationFolder);

There are three limitations: copying cross mailbox or to or from a Public Folder still won't return an Id. If you want to retrieve the moved copy of an item in those cases, we suggest you stamp it with a custom extended property before you move it and then use FindItems in the destination folder to find the moved copy.


这篇关于移动后如何继续使用EmailMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆