获取已发送电子邮件的文本正文以及正在回复的电子邮件的文本正文。 [英] Get the textual body of a sent email, as well as the textual body of the email that is being replied to.

查看:90
本文介绍了获取已发送电子邮件的文本正文以及正在回复的电子邮件的文本正文。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


我对回复之前电子邮件的电子邮件感兴趣。我想得到这种电子邮件的文本,以及"刺激"。回复的文本(对话中的上一封电子邮件)。


我可以相当轻松地加载用户的已发送电子邮件,这些电子邮件对应于已发送的电子邮件。 


我是新来的托管API,我知道一些名为"对话"的内容这可能有所帮助。


否则,我很乐意尝试使用启发式方法拆分原始文本电子邮件。获取原始电子邮件的最佳方式是什么?


我也不确定MIME是如何适应这种情况的!


非常感谢!

解决方案

对话将是一种很好的方法,因为您可以使用新的GetConversationItems方法(Exchange 2013中的新方法) )抓住对话中的所有消息。这是一个查找收件箱中第一个项目的示例,然后获取对话中的所有项目,
但忽略已删除项目和草稿文件夹中的项目(可配置)。


< pre class ="prettyprint"> static void GetConversationItemsSingleConversation(ExchangeService service)
{
try
{
//查找收件箱中的前X项。
FindItemsResults< Item> results = service.FindItems(WellKnownFolderName.Inbox,
new ItemView(1));

//获取项目的会话标识符。
ConversationId convId = results.Items [0] .ConversationId;

//指定对话中的项目返回的
//属性。
PropertySet properties = new PropertySet(BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived,EmailMessageSchema.TextBody);

//确定要忽略的文件夹。
Collection< FolderId> foldersToIgnore = new Collection< FolderId>(){WellKnownFolderName.DeletedItems,WellKnownFolderName.Drafts};

//请求会话项目。这导致对服务的调用。
ConversationResponse response = service.GetConversationItems(convId,
properties,
null,
foldersToIgnore,
ConversationSortOrder.TreeOrderDescending);

//获取会话的同步状态。
Console.WriteLine(" SyncState:" + response.SyncState);

Collection< Item> items = new Collection< Item>();

//处理会话项目的每个节点。
foreach(response.ConversationNodes中的ConversationNode节点)
{
Console.WriteLine(" Conversation node items:");

//处理对话节点中的每个项目。
foreach(node.Items中的项目项)
{
Console.WriteLine(" Item ID:" + item.Id.UniqueId);
Console.WriteLine(" Subject:" + item.Subject);
Console.WriteLine(" Received:" + item.DateTimeReceived);
Console.WriteLine(" Text body:" + item.TextBody);
Console.WriteLine("");
items.Add(item);
}
}
}
//如果服务出错,可能会发生此异常。
catch(ServiceResponseException srException)
{
Console.WriteLine(srException);
}
}




有关对话的其他信息,请访问:
如何:在Exchange中使用EWS处理对话


Hello!

I'm interested in emails which are replies to previous emails. I want to get the text of this kind of email, and the "stimulus" text that the reply is to (the previous email in the conversation).

I can fairly easily load the user's Sent emails, which correspond to sent emails. 

I'm new to the managed API, and I'm aware of something called "conversations" which might help.

Otherwise, I'm happy to try to split the raw textual email using heuristics. What is the best way to get the raw email?

I'm also not sure how MIME fits into this!

Many thanks!

解决方案

Conversations would be a good approach, as you can use the new GetConversationItems method (new in Exchange 2013) to grab all the messages in the conversation. Here's a sample that finds the first item in your inbox, then gets all items in the conversation, but ignores items in the Deleted Items and the Drafts folder (which is configurable).

 static void GetConversationItemsSingleConversation(ExchangeService service)
        {
            try
            {
                // Find the first X items in the inbox.
                FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox,
                                                                   new ItemView(1));

                // Get the conversation identifiers for the items. 
                ConversationId convId = results.Items[0].ConversationId;

                // Specify the properties that will be 
                // returned for the items in the conversation.
                PropertySet properties = new PropertySet(BasePropertySet.IdOnly,
                                                          ItemSchema.Subject,
                                                          ItemSchema.DateTimeReceived, EmailMessageSchema.TextBody);

                // Identify the folders to ignore.
                Collection<FolderId> foldersToIgnore = new Collection<FolderId>() { WellKnownFolderName.DeletedItems, WellKnownFolderName.Drafts };

                // Request conversation items. This results in a call to the service.         
                ConversationResponse response = service.GetConversationItems(convId,
                                                                               properties,
                                                                               null,
                                                                               foldersToIgnore,
                                                                               ConversationSortOrder.TreeOrderDescending);

                // Get the synchronization state of the conversation.
                Console.WriteLine("SyncState: " + response.SyncState);

                Collection<Item> items = new Collection<Item>();

                // Process each node of conversation items.
                foreach (ConversationNode node in response.ConversationNodes)
                {
                    Console.WriteLine("Conversation node items:");

                    // Process each item in the conversation node.
                    foreach (Item item in node.Items)
                    {
                        Console.WriteLine("   Item ID: " + item.Id.UniqueId);
                        Console.WriteLine("   Subject: " + item.Subject);
                        Console.WriteLine("   Received: " + item.DateTimeReceived);
                        Console.WriteLine("   Text body: " + item.TextBody);
                        Console.WriteLine("");
                        items.Add(item);
                    }
                }
            }
            // This exception may occur if there is an error with the service.
            catch (ServiceResponseException srException)
            {
                Console.WriteLine(srException);
            }
        }


Additional info about conversations can be found here: How to: Work with conversations by using EWS in Exchange.


这篇关于获取已发送电子邮件的文本正文以及正在回复的电子邮件的文本正文。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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