vb.net - Get latest unread mail from specific folder using outlook -
i want download attachment specific folder not sent me.
i need download latest unread mail folder today's date.
so how do that?
here's code:
dim app microsoft.office.interop.outlook.application = nothing dim ns microsoft.office.interop.outlook._namespace = nothing dim inboxfolder microsoft.office.interop.outlook.mapifolder = nothing dim subfolder microsoft.office.interop.outlook.mapifolder = nothing dim destinationdirectory string = "c:\unreadmails" if not directory.exists(destinationdirectory) directory.createdirectory(destinationdirectory) end if try app = new microsoft.office.interop.outlook.application() ns = app.getnamespace("mapi") ns.logon(nothing, nothing, false, false) inboxfolder = ns.getdefaultfolder(microsoft.office.interop.outlook.oldefaultfolders.olfolderinbox) subfolder = inboxfolder.folders("unreadmails") 'folder.folders[1]; works console.writeline("folder name: {0}, entryid: {1}", subfolder.name, subfolder.entryid) console.writeline("num items: {0}", subfolder.items.count.tostring()) integer = 1 subfolder.items.count dim item microsoft.office.interop.outlook.mailitem = ctype(subfolder.items(i), microsoft.office.interop.outlook.mailitem) dim filepath string = path.combine(destinationdirectory, item.attachments(i).filename) item.attachments(i).saveasfile(filepath) next catch ex system.runtime.interopservices.comexception console.writeline(ex.tostring()) ns = nothing app = nothing inboxfolder = nothing end try
i managed got work doing way:
dim app microsoft.office.interop.outlook.application = nothing dim ns microsoft.office.interop.outlook._namespace = nothing dim inboxfolder microsoft.office.interop.outlook.mapifolder = nothing dim subfolder microsoft.office.interop.outlook.mapifolder = nothing dim destinationdirectory string = directory.getcurrentdirectory & "\output\" if not directory.exists(destinationdirectory) directory.createdirectory(destinationdirectory) end if try app = new microsoft.office.interop.outlook.application() ns = app.getnamespace("mapi") ns.logon(nothing, nothing, false, false) inboxfolder = ns.getdefaultfolder(microsoft.office.interop.outlook.oldefaultfolders.olfolderinbox) subfolder = inboxfolder.folders("checklist") 'folder.folders[1]; works try each collectionitem object in subfolder.items dim newemail outlook.mailitem = trycast(collectionitem, outlook.mailitem) if newemail nothing continue end if if newemail.attachments.count > 0 integer = 1 newemail.attachments.count dim filepath string = path.combine(destinationdirectory, newemail.attachments(i).filename) newemail.attachments(i).saveasfile(filepath) next end if next collectionitem catch ex exception console.writeline(ex) end try catch ex system.runtime.interopservices.comexception console.writeline(ex.tostring()) ns = nothing app = nothing inboxfolder = nothing end try end sub
Comments
Post a Comment