vba - How can I make an outlook macro run whenever a unread item is in the mailbox? -
so, working on script takes emails , processes them in way. want work automatically without human interaction, part have done this.
the issue having if mailbox receives email whilst outlook closed, can not make program kick off because of email. if use
private sub application_startup() 'runs @ application start call processcode end sub
then runs , message hasn't been received yet can't processed.
i have tried
private sub application_newmail() 'runs whenever new mail item recieved call processcode end sub
but reason doesn't run in scenario (runs when mail received normally)
i have tried application_itemload
, , application_mapilogoncomplete
but neither of these seemed work.
what ideally want run code whenever unread mail item present in mail box, regardless of how got there.
thanks in advance
alex spicer
you may consider using timer checking unread emails periodycally. see outlook vba - run code every half hour more information. in timer's tick event can unread email using find/findnext or restrict methods of items class "[unread] = true"
criteria. read more these methods in following articles:
- how to: use find , findnext methods retrieve outlook mail items folder (c#, vb.net)
- how to: use restrict method retrieve outlook mail items folder
also i'd suggest handling newmailex event instead of newmail one.
this newmailex
event fired once every received item processed microsoft outlook. item can 1 of several different item types, example, mailitem, meetingitem, or sharingitem. entryidscollection string contains entry id corresponds item. note behavior has changed earlier versions of event when entryidcollection contained list of comma-delimited entry ids of items received in inbox since last time event fired.
the newmailex
event fired when new message arrives in inbox , before client rule processing occurs. can use entry id returned in entryidcollection array call namespace.getitemfromid method , process item. use method caution minimize impact on outlook performance. however, depending on setup on client computer, after new message arrives in inbox, processes spam filtering , client rules move new message inbox folder can occur asynchronously. should not assume after these events fire, one-item increase in number of items in inbox.
Comments
Post a Comment