vb.net - Looping over Outlook mail items in "Sent Items" folder -
we're trying access sent items folder in outlook 2007 (using exchange) test typeof(i) outlook.mailitem in below code snippet returns false.
we know have right folder because test items.count returns correct number of mail items.
inbox messages fine. if change folder olfoldersentmail olfolderinbox test typeof(i) outlook.mailitem passes , it's quite happy show subject.
dim app outlook.application = nothing dim ns outlook.namespace = nothing dim sifolder outlook.folder = nothing dim items outlook.items = nothing app = new outlook.application() ns = app.session sifolder = ctype(ns.getdefaultfolder(outlook.oldefaultfolders.olfoldersentmail), outlook.folder) items = sifolder.items msgbox(items.count) each in items if typeof (i) outlook.mailitem dim mailitem outlook.mailitem mailitem = ctype(i, outlook.mailitem) msgbox(mailitem.subject) else msgbox("not mailitem") end if next update
@rob's answer below, yes, has helped. i'm still puzzled. crucial thing @rob's code doing testing .messageclass = "ipm.note". if include later test typeof x mailitem succeeds. if replace @rob's test .messageclass = "ipm.note" if true then same code still executes later test mailitem fails. it's if testing .messageclass automagically resolves object mailitem.
furthermore sent items don't contain meeting requests test seem unnecessary anyway.
this should going ...
....
dim osent outlook.mapifolder = ons.getfolderfromid(gsententryid, gsentstoreid) dim oitems outlook.items = osent.items integer = 1 oitems.count 'test make sure item mail item , not meeting request. if oitems.item(i).messageclass = "ipm.note" if typeof oitems.item(i) microsoft.office.interop.outlook.mailitem .....
Comments
Post a Comment