How to permanently delete an mail item?

  • Thread starter Thread starter Bingo
  • Start date Start date
B

Bingo

I'm using the following code to do this but the item
stays int he Deleted Items folder. Why? Thanks.


Dim oMapiInbox As Outlook.MAPIFolder
Dim oMapiDelete As Outlook.MAPIFolder
Dim oMapiMail As Outlook.MailItem
Dim oMapiMailNew As Outlook.MailItem
Dim sMailID As String

Set oMapiInbox = oNsp.GetDefaultFolder(olFolderInbox)
Set oMapiDelete = oNsp.GetDefaultFolder
(olFolderDeletedItems)
Set oMapiMail = oMapiInbox.Items(1)

Set oMapiMailNew = oMapiMail.Move(oMapiDelete)
oMapiMailNew.Delete

Set oMapiMailNew = Nothing
Set oMapiMail = Nothing
Set oMapiInbox = Nothing
 
Outlook object model code that deletes something always puts it in Deleted
Items. "Hard" deleting an item can only be done using CDO 1.21 or Extended
MAPI or Redemption code. Or you could handle ItemAdd on the Deleted Items
folder and delete the items again there but you still may be prompted. The
other ways just permanently delete the item with no muss or fuss.




What's the reason behind this recommendation? Thanks.
 
Thanks, Ken,

What happens if I call the Delete method on the emails
after I first move them to the Deleted Items folder in
Outlook Object Model?

I also tested with the following code using CDO, but no
matter which Folder I chose to move the email to, the
Message is gone from my Outlook forever. What do I do
wrong? Thanks.

Set oSes = New MAPI.Session
With oSes
.Logon "", "", False, False
End With

Set oFld = oSes.GetDefaultFolder(CdoDefaultFolderInbox)
Set oFld1 = oSes.GetDefaultFolder(CdoDefaultFolderOutbox)
Set oMsgs = oFld.Messages
Set oMsg = oMsgs.Item(1)
Set oMsg1 = oMsg.MoveTo(oFld1.FolderID)

Set oSes = Nothing
Set oFld = Nothing
Set oMsgs = Nothing
Set oMsg = Nothing
Set oMsg1 = Nothing
 
If you delete items from Deleted Items they are gone, just as if you did it
from the UI.

Try using oFld1.ID and not FolderID. The information in the Object Browser
is confusing on that. If you look up the FolderID property in the CDO Help
file you will see it's defined as:

"The FolderID property returns the unique identifier of the subfolder's
parent folder as a string."
 
Without having any extensive knowledge of how OOM works I'd say this is
why your mail stays in the Delete folder cause you move it there before
deleting it
Set oMapiMailNew = oMapiMail.Move(oMapiDelete)
course I could be wrong. I'm more of a java person myself.
cheers
Steven
 
Back
Top