VB.net Outlook checking for mail and calender events -
hello have following code checks unread messages:
oinbox = ons.getdefaultfolder(outlook.oldefaultfolders.olfolderinbox).parent.folders(pair.key) oitems = oinbox.items oitems = oitems.restrict("[unread] = true") dim omsg outlook.mailitem integer = 1 oitems.count omsg = oitems.item(i) dim tmpstring string = "" tmpstring = omsg.subject & "^" & omsg.sendername & "^" & omsg.receivedtime & "^" & omsg.body & "^" & omsg.entryid outlookfoldersmail.add(dictionarynum, tmpstring) omsg = nothing dictionarynum += 1 next now works fine emails seems crash on line omsg = oitems.item(i) when trying process calender invite email.
the error this:
additional information: unable cast com object of type 'system.__comobject' interface type 'microsoft.office.interop.outlook.mailitem'. operation failed because queryinterface call on com component interface iid '{00063034-0000-0000-c000-000000000046}' failed due following error: no such interface supported (exception hresult: 0x80004002 (e_nointerface)).
what need add/and or check in order not crash if calender event invite?
code update
oinbox = ons.getdefaultfolder(outlook.oldefaultfolders.olfolderinbox).parent.folders(pair.key) oitems = oinbox.items oitems = oitems.restrict("[unread] = true")
dim omsg object integer = 1 oitems.count debug.print(oitems.class) omsg = oitems.item(i) dim tmpstring string = "" tmpstring = omsg.subject & "^" & omsg.sendername & "^" & omsg.receivedtime & "^" & omsg.body & "^" & omsg.entryid outlookfoldersmail.add(dictionarynum, tmpstring) omsg = nothing dictionarynum += 1 next i no longer have error on omsg = oitems.item(i) debug.print output 16 both normal email , calender invite....
you declaring omsg outlook.mailitem, meeting requests represented outlook.meetingitem objects.
declare omsg generic object , check class or messageclass property @ run-time decide how cast current item.
Comments
Post a Comment