This macro is made for a opsmgr management pack, soon to be published on this blog.

It is written in VBA in outlook 2010 (could work in other version too, but it is not tested).

It shows how to create a macro function, that is usable in a rule.

1. Enable Developer Ribbon to be able to create scripts

clip_image002

2. Open visual Basic

clip_image003

3. Select “ThisOutlookSession”

clip_image004

4. Type/ this Sub into Visual Basic. Changed the strExportPath to the folder you want to use.

Sub SaveMessageOnRule(Item As Outlook.MailItem)
	Dim strExportPath As String
	strExportPath = "C:\Temp\Mails\"
	Dim FileName As String
	FileName = strExportPath & Replace(Replace(Replace(Now & "_" & Item.EntryID & ".txt", ":", "_"), "-", "_"), " ", "_") 'Create filename and path, replace : with _, - with _ and space with _.
	Dim FileNum As Integer
	FileNum = FreeFile ' next file number
	Open FileName For Output As #FileNum ' creates the file if it doesn't exist
	Print #FileNum, Item.Body ' write information at the end of the text file
	Close #FileNum ' close the file
End Sub

5. Create rule in outlook

clip_image005

6. Select the coditions you want. Or none to process all emails

clip_image007

7. Select “run as Script” in the Select actions window, and choose the sub you have just created

clip_image009

8. Define exceptions if you have any, otherwise leave it blank.

clip_image011

9. Give your rule a name and save it.

clip_image013

10. You are now ready to setup the managementpack