如何在用户选择电子邮件时在“收件箱”窗格中获取鼠标单击事件

时间:2011-03-14 11:52:58

标签: c# .net ms-office outlook-2007 office-addins

我正在使用C#为Office 2007创建一个插件。只要用户在“收件箱”窗格中单击电子邮件列表中的电子邮件,此插件就会负责在新窗格中显示电子邮件标题信息。 现在,我不确定当用户选择电子邮件并阅读该电子邮件标题信息时,如何在“收件箱”窗格中显示鼠标单击事件。任何有用的指针?

2 个答案:

答案 0 :(得分:0)

您可以使用Microsoft V11.0 outlook对象库(添加引用),然后查询MAPI邮箱:

http://geekswithblogs.net/TimH/archive/2006/05/26/79720.aspx 要么 http://support.microsoft.com/kb/310258

使用MAPI或POP3访问交换收件箱的一些要求: C# MAPI to read exchange server inbox

现在,要获取已选择的收件箱消息,您可以使用:

Outlook.Explorer explorer = null;
explorer = outlookObj.ActiveExplorer();
            if (explorer.Selection.Count > 0)
            {
                var sel = explorer.Selection[1];
                if (sel is Microsoft.Office.Interop.Outlook.MailItem)
                {
                    var item = sel as MSOutlook.MailItem;
                    MessageBox.Show("Selected letter: "+item.Body);
                }
            }

答案 1 :(得分:0)

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {

       this.Application.Inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);          
    }
 void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            try
            {
                Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
                if (tmpMailItem != null)
                {
                    if (Inspector.CurrentItem is Outlook.MailItem)
                    {
                        tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
                        string to=   tmpMailItem.To;
                        string body = tmpMailItem.Body;
                    }
                }
             }
            catch
            {

            }
        }