You could try what's suggested in this question to store the EntryIDand retrieve it later using that same ID.
Saving object of Mailitem or any property which can be used to invoke Mailitem which was saved
-
19-04-2022 - |
Question
I am using VS 2010 , Dot Net Framework 2.0 . I have created a project in Extensibility->Shared Add-ins for Outlook.
I want to save Outlook.MailItem Object in a DataTable on explorer_SelectionChange() and use this Outlook.MailItem Object to Manipulate subject and body after-wards.
when i am saving Object of Mailitem in datatable it is getting saved as SYS.ComAddins. Here is the Code Class Variables :
private Outlook.MailItem connectingMailItem;
private Outlook.Inspectors inspectors;
private Outlook.Application applicationObject;
private object addInInstance;
private Outlook.Explorer explorer;
DataTable dtMailItem = new DataTable();
OnConnection :
explorer = this.Application.ActiveExplorer();
explorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(explorer_SelectionChange);
dtMailItem.Columns.Add("MailItem",typeOf(Outlook.MailItem));
tFollowUp = new Timer();
tFollowUp.Interval = 100000;
tFollowUp.Tick += new EventHandler(tFollowUp_Tick);
explorer_SelectionChange
void explorer_SelectionChange()
{
if (connectingMailItem != null && connectingMailItem is Outlook.MailItem)
{
Marshal.ReleaseComObject(connectingMailItem);
// Perform a Garbage Collection
GC.Collect();
connectingMailItem = null;
return;
}
foreach (object selectedItem in explorer.Selection)
{
connectingMailItem = selectedItem as Outlook.MailItem;
break;
}
if (connectingMailItem != null && connectingMailItem is Outlook.MailItem)
{
dtMailItem.Rows.Add(connectingMailItem);
dtMailItem.AcceptChanges();
}
}
tFollowUp_Tick
void tFollowUp_Tick(object sender, EventArgs e)
{
if(dtMailItem.Rows.Count <= 0)
{
foreach(DataRow dr in dtMailItem.Rows)
{
// Manipulation code for subject and body or remove the Mailitem from Datatable
}
}
}
How can i save Object of Mailitem or any Property to identify which Mailitem was saved
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow