如何编程Outlook 2007插件与多个邮箱

本文关键字:插件 2007 Outlook 何编程 编程 | 更新日期: 2023-09-27 18:16:20

我正试图弄清楚如何为Excel 2007编写一个简单的插件,但只能与我的一个邮箱交互。目前我有两个电子邮件地址进入我的outlook,每个都在一个特定的"邮箱"中。我想知道,如何为特定的邮箱指定NewMail事件?

或者,也许不那么干净,但是我怎么能写一个if函数来指定任何新项目的邮箱/电子邮件地址…

希望这是有意义的。由于

如何编程Outlook 2007插件与多个邮箱

要捕获新邮件事件,将以下代码添加到addin启动方法中:

this.Application.NewMailEx += 
    new Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);

然后添加处理NewMailEx事件的方法:

void Application_NewMailEx(string EntryID)
{
    // get MailItem for this new mail
    Outlook.Explorers explorers = this.Application.Explorers;
    Outlook.MailItem newMail =
        (Outlook.MailItem)explorers.Application.Session.GetItemFromID(EntryID, System.Reflection.Missing.Value);
    // check SendUsingAccount to see if it came in mailbox we are interested in
    if (newMail.SendUsingAccount.DisplayName == "your.name@your.domain.com")
    {
        // do whatever You like
    }
}  

添加using语句also:

using Outlook = Microsoft.Office.Interop.Outlook;