VB icon

Email NDR to Public Folder

Submitted on: 1/7/2015 2:31:00 PM
By: Scott Rutledge (from psc cd)  
Level: Intermediate
User Rating: By 2 Users
Compatibility: VbScript (browser/client side)
Views: 1276
     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.
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Email NDR to Public Folder
' Description: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.
' By: Scott Rutledge (from psc cd)

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
bstrPublicRootID = objInfoStore.Fields.Item( &H66310102 ).Value
Set objTopFolder = objSession.GetFolder(bstrPublicRootID, _
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()
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
Set objOneMessage = Nothing
Set objMessages = Nothing
Set objFolder = Nothing
Set objTopFolder = Nothing
Set objSession = Nothing

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.