Reputation: 45
Does anybody know if it is possible to find out if an email in my Inbox is a repsonse to a mail I have sent earlier?
Example: I send an email to person A with a question. When person A responds I would like to link my original mail to his response. My aim is to save the entire mail correspondance in a custom folder.
I have tried adding a MailItem.UserProperty to the E-mail object but apparently it doesn't get send.
An alternative solution I have thought about is to add an invisble text within the mail body that I can search when the response is recieved (assuming my original mail will be included in the response).
Upvotes: 1
Views: 1888
Reputation: 49405
The MailItem class provides the following properties for tracking conversations:
As you may see the conversation grouping depends on the subject line.
You can use the GetConversation method of the MailItem class to get a Conversation object that represents the conversation to which this item belongs. Be aware, GetConversation returns Null (Nothing in Visual Basic) if no conversation exists for the item. No conversation exists for an item in the following scenarios:
For example:
public void DemoConversation()
{
object selectedItem = Application.ActiveExplorer().Selection[1];
// This example uses only
// MailItem. Other item types such as
// MeetingItem and PostItem can participate
// in the conversation.
if (selectedItem is Outlook.MailItem)
{
// Cast selectedItem to MailItem.
Outlook.MailItem mailItem = selectedItem as Outlook.MailItem;
// Determine the store of the mail item.
Outlook.Folder folder = mailItem.Parent as Outlook.Folder;
Outlook.Store store = folder.Store;
if (store.IsConversationEnabled == true)
{
// Obtain a Conversation object.
Outlook.Conversation conv = mailItem.GetConversation();
// Check for null Conversation.
if (conv != null)
{
// Obtain Table that contains rows
// for each item in the conversation.
Outlook.Table table = conv.GetTable();
Debug.WriteLine("Conversation Items Count: " + table.GetRowCount().ToString());
Debug.WriteLine("Conversation Items from Table:");
while (!table.EndOfTable)
{
Outlook.Row nextRow = table.GetNextRow();
Debug.WriteLine(nextRow["Subject"] + " Modified: " + nextRow["LastModificationTime"]);
}
Debug.WriteLine("Conversation Items from Root:");
// Obtain root items and enumerate the conversation.
Outlook.SimpleItems simpleItems = conv.GetRootItems();
foreach (object item in simpleItems)
{
// In this example, enumerate only MailItem type.
// Other types such as PostItem or MeetingItem
// can appear in the conversation.
if (item is Outlook.MailItem)
{
Outlook.MailItem mail = item as Outlook.MailItem;
Outlook.Folder inFolder = mail.Parent as Outlook.Folder;
string msg = mail.Subject + " in folder " + inFolder.Name;
Debug.WriteLine(msg);
}
// Call EnumerateConversation
// to access child nodes of root items.
EnumerateConversation(item, conv);
}
}
}
}
}
void EnumerateConversation(object item, Outlook.Conversation conversation)
{
Outlook.SimpleItems items = conversation.GetChildren(item);
if (items.Count > 0)
{
foreach (object myItem in items)
{
// In this example, enumerate only MailItem type.
// Other types such as PostItem or MeetingItem
// can appear in the conversation.
if (myItem is Outlook.MailItem)
{
Outlook.MailItem mailItem = myItem as Outlook.MailItem;
Outlook.Folder inFolder = mailItem.Parent as Outlook.Folder;
string msg = mailItem.Subject + " in folder " + inFolder.Name;
Debug.WriteLine(msg);
}
// Continue recursion.
EnumerateConversation(myItem, conversation);
}
}
}
Upvotes: 2