How to Program Outlook 2007 Add-In with Multiple Mailboxes

I'm trying to figure how to write a simple add-in for Excel 2007, but one that only interacts with one of my mailboxes. Currently I have two email addresses coming into my outlook, each in a specific 'mailbox'. I was wondering, how would I specify a NewMail event for a specific mailbox?

Or, perhaps not as clean, but how could I write an if function that specifies which mailbox / email any new item is addressed to...

Hopefully this makes sense. Thanks

Answers


To catch new mail event, add this code to addin startup method:

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

Then add method to handle NewMailEx event:

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

Add using statement also:

using Outlook = Microsoft.Office.Interop.Outlook;  

Need Your Help

how to use jquery in my content pages?

c# javascript jquery asp.net jquery-ui

net c# web application and page that using master page

Rails Model has_many with multiple foreign_keys

ruby-on-rails ruby model has-many

Relatively new to rails and trying to model a very simple family "tree" with a single Person model that has a name, gender, father_id and mother_id (2 parents). Below is basically what I want to do...

Caching database query results in Zend Framework

php caching zend-framework

I'm a beginner in Zend and I'm getting some problems while trying to cache the database query results.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.