【问题标题】:Saving object of Mailitem or any property which can be used to invoke Mailitem which was saved保存 Mailitem 的对象或任何可用于调用已保存的 Mailitem 的属性
【发布时间】:2013-05-03 21:08:29
【问题描述】:

我正在使用 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

【问题讨论】:

  • 对不起,我不明白你的问题。你能发布一些代码来解释你想要得到的结果吗?

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-16
    • 2010-12-24
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 2013-12-23
    相关资源
    最近更新 更多