Delete a mailitem permanently in outlook -


i'm trying delete mailitem using outlook api. following,

dim objmail each objmail in objfolder.items objmail.delete next 

obviously, deleting item straight away simple. outlook move "deleted items" folder instead of deleting it. tried "deleted items" folder using

outlooknamespace.getdefaultfolder(oldeleteditems) 

and delete mail again, pst code working on not default mailbox , folder returned wrong deleted items folder. how can permanently delete mailitem?

i tried loop through folders in current store, there's no way of telling folder deleted items folder except comparing names, can't since programs used in multiple languages , name different each version.

ps: cannot use third party dll :(

help!

first problem of code not appropriate loop use. if want delete (almost in vba) need loop collection last element first. if not, change order of collection- after delete 1st element >> 2nd 1 moved 1st position , not deleted.

therefore code should delete items delteteditems folder:

sub delete_all_from_dust_bin()      dim myfolder outlook.folder      set myfolder = application.getnamespace("mapi"). _             getdefaultfolder(olfolderdeleteditems)      dim long     = myfolder.items.count 1 step -1          myfolder.items(i).delete      next  end sub 

obviously, prepare similar code deleting other folder. run both deletion loops remove items sure.

some additional remarks mailitem.delete method msdn:

the delete mothod deletes single item in collection. delete items in items collection of folder, must delete each item starting last item in folder. example, in items collection of folder, allitems, if there n number of items in folder, start deleting item @ allitems.item(n), decrementing index each time until delete allitems.item(1).

edit due comments op.

even if need delete items (not all) remember use loop type presented above. if need refer other deleteditems folder in other stores can find folder in these ways:

'with index reference application.getnamespace("mapi").stores(2).getdefaultfolder(olfolderdeleteditems) 'with name reference application.getnamespace("mapi").stores("business mail").getdefaultfolder(olfolderdeleteditems) 

i don't know if works outlook versions it's working outlook 2010.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -