Advertisement
6_2008-2009 Miscellaneous #207997

Email NDR to Public Folder

Run as a VBS from a scheduled task, logged in as the desired user, this script will move non-delivery reports (NDR) email to a public folder.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
CONST strServer   = "SERVER"
  CONST strMailbox   = "MAILBOX"
  Dim objSession
  Dim objMessages
  Dim objOneMessage
  Dim objInfoStores
  Dim objInfoStore
  Dim objTopFolder
  Dim objFolders
  Dim objInbox
  Dim objSubFolder
  Dim objTargetFolder
  Dim strProfileInfo
  Dim bstrPublicRootID
  Dim i

  strProfileInfo = strServer & vblf & strMailbox
  Set objSession = CreateObject("MAPI.Session")
  objSession.Logon , , False, , , True, strProfileInfo
  Set objInfoStores = objSession.InfoStores
  For i = 1 To objInfoStores.Count
  	If objInfoStores.Item(i)= "Public Folders" Then
    		Set objInfoStore=objInfoStores.Item(i)
    		Exit For
  	End If
  Next
  bstrPublicRootID = objInfoStore.Fields.Item( &H66310102 ).Value
  Set objTopFolder = objSession.GetFolder(bstrPublicRootID, _
        objInfoStore.ID)
  Set objFolders = objTopFolder.Folders
  Set objFolder = objFolders.GetFirst()
  i = 0
  Do Until objFolder.Name = "Public Folder Name"
  	i = i + 1
  	If i > 100 Then 'kill the search
 		Exit Do
  	End If
  	Set objFolder=objFolders.GetNext()
  Loop
 
  For i = 1 to 3 '3 passes enough to grab everything
  	Set objInbox = objSession.Inbox
  	Set objMessages = objInbox.Messages
  	For Each objOneMessage in objMessages
   		If objOneMessage.Type = "REPORT.IPM.Note.NDR" Then
  			Set objCopyMsg = objOneMessage.MoveTo(objFolder.ID)
		End If
  	Next
  Next
  objSession.Logoff
  Set objOneMessage = Nothing
  Set objMessages = Nothing
  Set objFolder = Nothing
  Set objTopFolder = Nothing
  Set objSession = Nothing
Original Comments (3)
Recovered from Wayback Machine