0

I try to build a Add-In that saves Attachments form a Mail with a specific Subject. Till now that works fine, but i think that im using the wrong Eventhandler for my needs.

It should start if a new Mail comes in, and then check the whole Inbox + the new mail.

atm im using Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailEventHandler()
so he just looking for the Inbox without the new item, because at that moment the new mail isnt part of the inbox

  private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {                 
        this.Application.NewMail += new Microsoft.Office.Interop.Outlook
        .ApplicationEvents_11_NewMailEventHandler(ThisAddIn_NewMail);


    }

What can i do instead ?

RobertZ
  • 3
  • 1

1 Answers1

0

You can assume that the email will be unread, so you should be able to use Items.Find/FindNext to look for the unread messages. Or you can store the date of the last processed e-mail and, again, use Items.Find/FindNext to search for messages with CreationTime greater than some value.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • good idea, but i think the incoming mail item do not exist while my Add-In is running, because the "NewMail" Event starts before the new item is stored in the inbox so i cant search for the new mail that's my interpretation... – RobertZ Jun 28 '13 at 09:21
  • By the time NewMail fires, the item is accessible. More than that, you can use NewMailEx event, which actually passes the entry id of the new message. Now the problem is that if you are accessing an Exchange mailbox, the message can arrive when Outlook (and your code) is not running. Then when Outlook starts up, no events will fire in the online mode (all you have is a new unread message in the Inbox) or, in case of the cached mode, Items.ItemAdd even will fire on the Inbox folder when the new messages is synchronized to the local (cached) store. – Dmitry Streblechenko Jun 28 '13 at 17:50
  • Thanks a lot! with this info and a little bit help form this post: http://stackoverflow.com/questions/8562214/itemadd-event-on-a-public-folder-on-exchange i succeeded :D – RobertZ Jul 01 '13 at 07:31