保存Mailitem的对象或可用于调用已保存的Mailitem的任何属性

时间:2013-05-09 11:41:43

标签: c# outlook outlook-addin comaddin shared-addin

我正在使用VS 2010,Dot Net Framework 2.0。我在Extensibility中创建了一个项目 - > Outlook的共享加载项。

我想在explorer_SelectionChange()上的DataTable中保存Outlook.MailItem对象,并使用此Outlook.MailItem对象来操作后面的主题和正文。

当我在数据表中保存Mailitem的对象时,它将被保存为SYS.ComAddins。 这是守则 类变量:

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

如何保存Mailitem对象或任何属性以识别保存哪个Mailitem

1 个答案:

答案 0 :(得分:1)

您可以尝试this question中建议的内容来存储EntryID,稍后使用相同的ID检索它。