![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi,
Im trying to catch all incoming new mail using the code below. The problem is that it is only run once, so when i get 3 new messages, only the first mail will be used in the eventhandler. -- private void ThisAddIn_Startup(object sender, System.EventArgs e) { Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDef aultFolders.olFolderInbox); inbox.Items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(inboxFolde rItemAdded); } public void inboxFolderItemAdded(object item) { if (item is Outlook.MailItem) { Outlook.MailItem mail = (Outlook.MailItem)item; MessageBox.Show(mail.Subject.ToString()); } } |
Ads |
#2
|
|||
|
|||
![]()
Declare the inbox object at class level and not in ThisAddIn_Startup and I'd
recommend also declaring an object for inbox.Items and attaching the event handler to that instead of to inbox.Items as you are doing. The way that object is declared it's going out of scope and is being garbage collected. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Dave" wrote in message ... Hi, Im trying to catch all incoming new mail using the code below. The problem is that it is only run once, so when i get 3 new messages, only the first mail will be used in the eventhandler. -- private void ThisAddIn_Startup(object sender, System.EventArgs e) { Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDef aultFolders.olFolderInbox); inbox.Items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(inboxFolde rItemAdded); } public void inboxFolderItemAdded(object item) { if (item is Outlook.MailItem) { Outlook.MailItem mail = (Outlook.MailItem)item; MessageBox.Show(mail.Subject.ToString()); } } |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Windows Installer runs | Invisible | Outlook - General Queries | 2 | October 3rd 06 09:53 AM |
Macro runs on startup | jbc | Outlook - Installation | 1 | September 20th 06 07:40 PM |
ThisOutlookSession - code runs only once | Rafael1119 | Outlook and VBA | 8 | July 17th 06 11:51 AM |
Outlook 2003 "find" contacts doesn't work, just runs and runs | Tom Stanley | Outlook - Using Contacts | 1 | July 5th 06 03:56 AM |
Outlook Express runs without .exe | DiscoNap9000 | Outlook Express | 3 | May 29th 06 11:18 PM |