none
understanding NewMailEx event RRS feed

  • Question

  • So , I have some questions regarding NewMailEx event . 

    1.This event works only for the primary outlook account? For example , if I have 2 accounts in outlook, one imap and one pop3 , imap being the primary one, it will work only for it? And if yes, what should I do for searching new mails in every account? 

    2.In the newmailex event , I'm adding a message to the subject and then I'm moving that mail to a different folder. Sometimes, I see that when I click a mail from the folder I made , the mail makes a copy of himself and goes to inbox so now I'm having 2 mails. One in the folder I made (and where I want the mails to be moved) and one in Inbox(with the subject changed) . Does anybody knows why?

    3. How are the mails processed using newmailex ? Async or Sync?

    That's it for now. If I'll have more questions, I'll post it here.

    Tuesday, June 10, 2014 9:01 AM

Answers

All replies

  • Hello,

    1. The event is fired for all mailboxes/items received (in theory). Be aware, if a lot of items are received the event will not be fired - a known issue. See Handling NewMail, NewMailEx and ItemAdd Outlook events in .NET . I'd recommend reading the NewMailEx description on MSDN:

    This event fires once for every received item that is processed by Microsoft Outlook.

    2. It looks like the issue comes from your code. What code do you use? Is it an Outlook add-in or VBA macro?

    3. Sync. All operation with the Outlook object model should be run on the main thread (UI). You may notice that if you start a long-running task the UI is freezed.

    You may find the following series of articles helpful

    Outlook NewMail unleashed:


    • Edited by Eugene Astafiev Tuesday, June 10, 2014 10:06 AM
    • Marked as answer by intenesi Tuesday, June 10, 2014 11:02 AM
    Tuesday, June 10, 2014 9:24 AM
  • Ok, I've tested more and I see that NewMailEx event fires for every account. Now my problem is that I create a folder where I move the newmails that contain a specific subject. 

    The fuction looks like this: 

    Outlook.Folder destfolder;

    private void CreateFolderOnStartup() { try { Outlook.Folder inBox = (Outlook.Folder)this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.Folder parent = inBox.Parent as Outlook.Folder; bool exist = false; foreach (Outlook.Folder cst in parent.Folders) { if (cst.Name.Contains("Test")) { exist = true; destfolder = cst; } } if (!exist) { destfolder = (inBox.Parent).Folders.Add("Test"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }

    Me having 2 accounts on Outlook, an IMAP and a POP3 , imap being the primary , it creates me a "Test" folder on the IMAP account. Now, if I send an mail on the POP3 account which should move it to my folder, it moves it to the "Test" of IMAP and it's not creating a new folder on the POP3 section (which I would like) . How can I make this possible?

    Also, you said that NewMailEx handles 16 messaged at a time but I saw on this article  that the event can handle almost 1000 mails. I've tested my application with 100 mails and it seems to work. 


    • Edited by intenesi Tuesday, June 10, 2014 10:02 AM
    Tuesday, June 10, 2014 9:31 AM
  • According to your code you create a older in default delivery store. So, it works as it should. If you want to get the folder created in a particular store you need to use GetDefaultFolder method of the Store class (not Namespace).  

    The NewMailEx event will not be fired if multiple of items are arrived at once. Didn't test it in latest Outlook versions, but for ItemAdd and etc. events the limitation remains the same - 16 items. As a workaround you can use a timer for checking unprocessed emails.

    Tuesday, June 10, 2014 12:24 PM