none
Problem with event firing on incomming emails RRS feed

  • Question

  • Hi,

    I have problem with handling events for incomming messages.
    (Outlook 2012, Win7 x64, C# AddIn)

    I want to be notified when new email has been received or send. I've registered to "Application.NewMailEx", "Application.ItemSend" and to each folder (and subfolder) of inbox (OlDefaultFolders.olFolderInbox) to events "Items.ItemAdd" and "Items.ItemChange" and to same events of send folder (OlDefaultFolders.olFolderSentMail).

    The event for "Items.ItemAdd" or "Items.ItemChange" is not fired when user has received an email(s) when Outlook is not running and user just launched this application. From trace log I can see that events are registered, synchronization with Exchange is done and emails in inbox or in it's subfolder appears, but event handler method is not called at all.

    If Outlook (without closing it) is running for longer time (a few minutes?) and user performs operations like send/receive, the events starts being fired! Missing events happen when application is started and initial synchronization is performed. It happened that Outlook has been started and events WERE fired!

    I've looked through this forum and others. All found proposed solution has been tried:
    - cache mode is enabled
    - caching Items objects in root list in AddIn (caching all folders and event handlers to, just in case)
    - has been tested at least with receiving 1, 3, more emails at once

    Please advice if anyone has spotted similiar problem and what is solution to it.

    Thanks!
    Wojciech Gebczyk


    Wednesday, October 31, 2012 9:20 AM

Answers

  • If Outlook was not running and emails were placed into Inbox by Exchange no events will fire for that and none are expected. On startup you must mark and check any items that were not processed previously in Inbox.
     
    If more than 15 items come in at once your events also probably won't fire. You will need to sweep the Inbox periodically to check for items not processed previously.
     
    I usually mark items with a user property or MAPI named property to indicate they were processed already. Then a simple search on the folder items for items without the property returns any unprocessed itms.
     
    A periodic sweep must not run in a background thread and use the Outlook object model. The object model cannot be run from anything but the main thread.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "wgebczyk" <=?utf-8?B?d2dlYmN6eWs=?=> wrote in message news:61a8a572-1bdd-4027-9af0-7bfab1e69e1b...
    Hi,

    I have problem with handling events for incomming messages.
    (Outlook 2012, Win7 x64, C# AddIn)

    I want to be notified when new email has been received or send. I've registered to "Application.NewMailEx", "Application.ItemSend" and to each folder (and subfolder) of inbox (OlDefaultFolders.olFolderInbox) to events "Items.ItemAdd" and "Items.ItemChange" and to same events of send folder (OlDefaultFolders.olFolderSentMail).

    The event for "Items.ItemAdd" or "Items.ItemChange" is not fired when user has received an email(s) when Outlook is not running and user just launched this application. From trace log I can see that events are registered, synchronization with Exchange is done and emails in inbox or in it's subfolder appears, but event handler method is not called at all.

    If Outlook (without closing it) is running for longer time (a few minutes?) and user performs operations like send/receive, the events starts being fired! Missing events happen when application is started and initial synchronization is performed. It happened that Outlook has been started and events WERE fired!

    I've looked through this forum and others. All found proposed solution has been tried:
    - cache mode is enabled
    - caching Items objects in root list in AddIn (caching all folders and event handlers to, just in case)
    - has been tested at least with receiving 1, 3, more emails at once

    Please advice if anyone has spotted similiar problem and what is solution to it.

    Thanks!
    Wojciech Gebczyk



    Ken Slovak MVP - Outlook
    Wednesday, October 31, 2012 4:26 PM
    Moderator

All replies

  • just to be sure: outlook 2012? do you mean 2010 or 2013?

    and show us simplest code that reproduces issue.

    Also please try to find out if those 'missing' data events happen when lots of mails are synchronized, or even if just one or two mails are at all in whole mailbox.

    Wednesday, October 31, 2012 11:39 AM
  • I'm sorry :-)

    Outlook 2010, VS2012, Win7 x64.

    The simplest addin that just register to events and write trae information works fine.

    Putting additional code to event handlers, startup - stops receiving events.

    Any additional information would be helpful?

    Thanks!

    EDITED: I have tried with more than 16 mail messages too just to discard from mystic issue with more than 10/16 mails.
    • Edited by wgebczyk Wednesday, October 31, 2012 12:09 PM
    Wednesday, October 31, 2012 12:08 PM
  • yes, additional code that exposes that problem would be helpful - just comment out parts of your event handlers and see when it starts working again. Use this technique to pinpoint exact line that causes the bug, then show us this code.
    Wednesday, October 31, 2012 1:52 PM
  • If Outlook was not running and emails were placed into Inbox by Exchange no events will fire for that and none are expected. On startup you must mark and check any items that were not processed previously in Inbox.
     
    If more than 15 items come in at once your events also probably won't fire. You will need to sweep the Inbox periodically to check for items not processed previously.
     
    I usually mark items with a user property or MAPI named property to indicate they were processed already. Then a simple search on the folder items for items without the property returns any unprocessed itms.
     
    A periodic sweep must not run in a background thread and use the Outlook object model. The object model cannot be run from anything but the main thread.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "wgebczyk" <=?utf-8?B?d2dlYmN6eWs=?=> wrote in message news:61a8a572-1bdd-4027-9af0-7bfab1e69e1b...
    Hi,

    I have problem with handling events for incomming messages.
    (Outlook 2012, Win7 x64, C# AddIn)

    I want to be notified when new email has been received or send. I've registered to "Application.NewMailEx", "Application.ItemSend" and to each folder (and subfolder) of inbox (OlDefaultFolders.olFolderInbox) to events "Items.ItemAdd" and "Items.ItemChange" and to same events of send folder (OlDefaultFolders.olFolderSentMail).

    The event for "Items.ItemAdd" or "Items.ItemChange" is not fired when user has received an email(s) when Outlook is not running and user just launched this application. From trace log I can see that events are registered, synchronization with Exchange is done and emails in inbox or in it's subfolder appears, but event handler method is not called at all.

    If Outlook (without closing it) is running for longer time (a few minutes?) and user performs operations like send/receive, the events starts being fired! Missing events happen when application is started and initial synchronization is performed. It happened that Outlook has been started and events WERE fired!

    I've looked through this forum and others. All found proposed solution has been tried:
    - cache mode is enabled
    - caching Items objects in root list in AddIn (caching all folders and event handlers to, just in case)
    - has been tested at least with receiving 1, 3, more emails at once

    Please advice if anyone has spotted similiar problem and what is solution to it.

    Thanks!
    Wojciech Gebczyk



    Ken Slovak MVP - Outlook
    Wednesday, October 31, 2012 4:26 PM
    Moderator
  • If the last thing is true, then this might be the case.

    Some operations are running from TreadPool thread and are making operations on OL objects.

    I'll try putt all operations via main UI thread.

    Thanks!

    Wednesday, October 31, 2012 8:47 PM
  • Hi wgebczyk,

    Thanks for posting in the MSDN Forum.

    Would you please tell me whether your have solved your issue. If you have solved, would you please share your experience here? And I will mark Ken's reply as answer, please feel free to unmark it if you don't think so.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us


    Wednesday, November 7, 2012 6:06 AM
    Moderator