Private Sub Application_NewMailEx(ByVal EntryIDs As String)
'This will capture a reference for EVERY post item, not just the first
Dim olApp As Outlook.Application
Dim mapiNS As NameSpace
Dim idArray() As String
Dim postObject As Object
Dim ts as TextStream
Dim fs as Scripting.FileSystemObject
Dim f as Object
Set olApp = Outlook.Application
Set mapiNS = olApp.GetNamespace("MAPI")
Set fs = CreateObject("Scripting.FileSystemObject")
'Change to your log file. If you want to create a new file, I believe it's fs.CreateFile?
Set f = fs.GetFile("C:/Path/LogFile.txt")
Set ts = f.OpenAsTextStream(ForAppending)
'Here's where we start to loop through the post items
idArray = Split(EntryIDs, ",")
For i = 0 To UBound(idArray)
Set postObject = mapiNS.GetItemFromID(idArray(i))
If postObject.Class = olMail Then
'You need to determine a logic to specify your emails
If (InStr(postObject.Subject, "LogFileExampleString") > 0 Then
'And how you want the line formatted
ts.writeline Format(Now(), "yyyy-mm-dd hh:mm.ss") &", "& Replace(postObject.Body, Chr(10), "")
End If
End If
Next i
Set olApp = Nothing
Set mapiNS = Nothing
Set inboxFolder = Nothing
Set taskFolder = Nothing
Set postObject = Nothing
Set request = Nothing
Set fs = Nothing
Set f = Nothing
Set ts = Nothing
End Sub