Visual Studio 2008′s Outlook Add-in projects allows you to create add-ins that can customize almost any feature of Ms Outlook.
Two useful events that can be captured are ReminderFire and NewMailEx. The first occurs before a reminder of a calendar item
is executed. And the second occurs when a new email is received in the Inbox.
using Outlook=Microsoft.Office.Interop.Outlook;
using System.Windows.Forms; //for MessageBox object
privateOutlook.Explorers _Explorers; // the Outlook Explorers collection
privateOutlook.Inspectors _Inspectors; // the Outlook Inspectors collection
privateOutlook.NameSpaceoutlookNamespace;
privatevoidThisAddIn_Startup(objectsender,System.EventArgse)
{
_Explorers=this.Application.Explorers;
_Inspectors=this.Application.Inspectors;
_Explorers.Application.NewMailEx+=new
Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
_Explorers.Application.Reminders.ReminderFire+=new
Outlook.ReminderCollectionEvents_ReminderFireEventHandler(Application_ReminderFire);
outlookNamespace=this.Application.GetNamespace("MAPI");
}
privatevoidApplication_ReminderFire(Outlook.Reminder reminder)
{
MessageBox.Show(reminder.Caption,"New Reminder",MessageBoxButtons.OK);
}
privatevoidApplication_NewMailEx(stringEntryID)
{
Outlook.MailItem newMail=(Outlook.MailItem)_Explorers.Application.Session.GetItemFromID(
EntryID,System.Reflection.Missing.Value);
if(newMail.Subject!=null)
{
MessageBox.Show("From: "+newMail.SenderEmailAddress+"\nSubject: "+
newMail.Subject,"New Email",MessageBoxButtons.OK);
}
else
{
MessageBox.Show("You've got mail.");
}
}
customoutlookprompt.zip (52.35 kb)
2f92b5e0-c02f-487a-8cb0-d11dbb97ff3c|1|5.0
Categories:
C#
19. May 2012
Tags:
Capturing Outlook New Mail and Reminder Events