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_mapilogoncompletebut 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:

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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -