0

我正在使用 VS 2010 ,Dot Net Framework 2.0 。我在 Extensibility->Shared Add-ins for Outlook 中创建了一个项目。

我想将 Outlook.MailItem 对象保存在 explorer_SelectionChange() 上的 DataTable 中,然后使用此 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();

连接:

    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

4

1 回答 1

1

您可以尝试此问题中的建议来存储 EntryID 并稍后使用相同的 ID 检索它。

于 2013-05-09T12:13:04.710 回答