Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Delete Mail Outlook OLE
Here's an Outlook sample that should be adaptable... objOutlook = ObjectOpen("Outlook.Application") oln = objOutlook.GetNameSpace("MAPI") oln.logon(uid, pwd, 0, 1) ; sent items folder = 5, deleted items folder = 3, inbox = 6 dfolder = oln.getdefaultfolder(5) ;dfolder = oln.getdefaultfolder(3) ditems = dfolder.items ccount = 0 for aa = 1 to 1000 x = ditems.count dmsg = dfolder.items(x) ; message("Subject", dmsg.subject) if timediffdays(rnow, dmsg.senton) > 4 ; message("Sent Date", "should be deleted") dmsg.delete ccount = ccount + 1 else x = x - 1 endif next oln.logoff objectclose(objOutlook)
User comments...
Outlook is a bit weird since it updates the folder's contents dynamically, so that if you have 100 items in your folder, you delete one it now knows it has 99. This however moves all the lower messages up one so that you may process an item a few times or that it skips others. I found that even using VB I had the same problem where it would skip emails that it should've taken care of, hence why the loop is set to 1000. I tried decrementing the loop counter after each delete, but that seemed not to produce a remedy. The remedy for this being executing the loop 3 or 5 times to cover any misses.
I had a VB programmer try and he ran into the same problem where it would skip certain messages, while it would deal with others, but he couldn't explain why......
Further Feedback...
If it is desired to process mail, and delete one or more specific mail items, I have found the following partial code to solve the "lost place" problem:
count = 0 count = ditems.count for aa = 1 to count dmsg = dfolder.items(aa) ; message("Subject", dmsg.subject) if timediffdays(rnow, dmsg.senton) > 4 ; message("Sent Date", "should be deleted") dmsg.delete aa = aa - 1 count = count - 1 endif next
Article ID: W14681
Filename: Delete Mail from Outlook using OLE.txt
File Created: 2005:01:27:15:19:20
Last Updated: 2005:01:27:15:19:20