Delete old emails

Outlook version
Outlook 2013 32 bit
Email Account
Exchange Server 2010

Trying to resolve a problem with deleting 30 old specific emails.
Emails are located in outlook folder and trying to extract Message-ID for each email (as it's unique) export it. And then use that info and run powershell command to delete that email.

Looking for options how to extract only Message-Id(email header) from outlook folder and save it to a file?

Any ideas guys?



Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Are you only deleting some of the messages in the folder?

Message_id is PR_INTERNET_MESSAGE_ID - how to get it sample is here - Read MAPI properties not exposed in Outlook's Object Model

The entry id is objectname .EntryID

This shows show to get the full header and write it to a file (in the form of a new message) using VBA - Get Outlook's Internet Headers using VBA

writing to a text file is fairly simple:

Dim objFS As New Scripting.FileSystemObject, objFile As Scripting.TextStream
StrFile = "C:\folder\" & sName & ".txt"
Set objFile = objFS.CreateTextFile(StrFile, False)
If objFile Is Nothing Then
MsgBox "Error creating file '" & StrFile & "'.", vbOKOnly + vbExclamation _
, "Invalid File"
Exit Sub
End If

With objFile
.Write "<a href='" & strURL & "'><strong>" & strSubject & "</strong></a> <br />" & vbCrLf
.Write strBody & "<br /><br />" & vbCrLf & vbCrLf
End With


the With objfile block should be inside the loop that gets the message id:
'get new message
'code to get message ld
'write it to file
'loop to next new message

Similar threads