Internet Handholding posted on October 08, 2009 17:45
This code uses the Outlook Application_ItemSend Event to check the email message before sending.
To get the code to run you must have the proper security setup. For self signing a certificate see Outlook-Macros.blogspot.com or Enable Outlook macros by self signing a certificate with selfcert.exe.
This code initializes the Outlook_Email_Item_Send_Class that does all the work for checking the email message.
To get this code to work, you have to do these things.
- In Outlook go to Tools, Macro, Visual Basic Editor, right click Project 1, Insert, Module. Change the module name to Outlook_Email_Item_Send_Class by clicking on the module name in the properties window which by default is in the lower part of the left side. Copy the code from Outlook_Email_Item_Send_Class that is here.
- Click the ThisOutlookSession object and copy the code below for the Application_ItemSend Event.
- After the line than starts Set emailchecker, change any of the emailchecker properties that appeal to you.
- Enable Outlook macros by self signing a certificate with selfcert.exe
- Send an email and hope this works. Good luck.
'----------------------------------------------------
'Calls the Outlook_Email_Item_Send_Class to check the email
'----------------------------------------------------
Private Sub Application_ItemSend(ByVal item As Object, cancel As Boolean)
Dim email As mailitem
Set email = item
If email.Class <> olMail Then Exit Sub 'Make sure it is a mail message and not a task or something else
Dim emailchecker As Outlook_Email_Item_Send_Class
Set emailchecker = New Outlook_Email_Item_Send_Class
If Not emailchecker.Item_Send_Check(email) Then
cancel = True
email.Display
End If
End Sub