Script to mass forward emails to user

There are situations, e.g., a migration to a new system/server/client, when IT may decide to archive all your Notes emails older than <n months/years>, thus making them unaccessible for a quick search. To avoid any unexpected disruption in your work flow you could iterate through the emails to be archived and forward them to yourself so that they become more “recent”. Below is the LotusScript code for a Notes agent that does this; tested in 8.5.1.

You need to edit your company’s domain name below (variable sendTo$). By default, emails are forwarded to the auto-detected current user (variable user$). The Sleep command was added to prevent “clogging” of the servers. Script runs in modal mode in the UI thread, but you get a chance to cancel execution before it starts forwarding emails.


%REM

This script forwards the selected items in a Lotus Notes folder to current user (tip: to make them 'recent')

%END REM

%INCLUDE “lsconst.lss”

Sub Initialize

On Error Goto Trap	

’ Create a new session

Dim s As New NotesSession 

’ Get a handle to the current database

Dim db As NotesDatabase

Set db = s.CurrentDatabase

’ Get a collection of selected documents

Dim colSelected As NotesDocumentCollection

Set colSelected = db.UnprocessedDocuments



If ( colSelected.Count = 0 ) Then

	' Print "* No documents selected... "

	Messagebox "No documents selected", MB_OK + MB_ICONINFORMATION + MB_APPLMODAL, "ForwardMe - Info"

	Exit Sub

Else

	Dim sendTo As String

	Dim user As String

	user$ = s.CommonUserName

	user$ = Lcase$ ( Strleft ( user$, " " ) & "." & Strright ( user$, " " ) )

	sendTo$ = user & "@<your_company_domain_name_here>"

	

	' Print "* Processing " & colSelected.Count & " documents... "

	Dim answer As Integer

	answer% = Messagebox ( "Forward " & colSelected.Count & " documents to '" & sendTo & "'?", MB_YESNO + MB_ICONQUESTION + MB_APPLMODAL, "ForwardMe - Confirm"	)

	

	If ( answer% = IDYES ) Then		

		Dim doc As NotesDocument

		Dim newDoc As NotesDocument

		

		Set doc = colSelected.GetFirstDocument

		

		Do Until ( doc Is Nothing )

			Set newdoc = db.CreateDocument

			Call doc.CopyAllItems ( newdoc, True ) 

			newdoc.Subject = "Fwd: "& newdoc.Subject ( 0 ) 

			newdoc.CopyTo = "" 

			newdoc.BlindCopyTo = "" 

			Call newdoc.Send ( False, sendTo$ )	

			

			' Forward up to 3 emails / s

			Sleep ( 0.3 )

			Set doc = colSelected.GetNextDocument ( doc )

		Loop		

		

		' Print ( "* Success forwarding " & colSelected.Count & " email messages to  '" & sendTo & "'")

		Messagebox "Success forwarding " & colSelected.Count & " email messages to '" & sendTo & "'", MB_OK + MB_ICONINFORMATION + MB_APPLMODAL, "ForwardMe - Info"

	End If

End If

’ Exit now, avoid Trap :slight_smile:

Exit Sub	

’ Catch exception

Trap:

On Error Resume Next

' Print ( Cstr ( Err ) & " " & Error$ )

Messagebox "Exception:  " & Cstr ( Err ) & " " & Error$, MB_OK + MB_ICONEXCLAMATION + MB_APPLMODAL, "ForwardMe - Exception"

End	

End Sub