Navigation

Search

Categories

On this page

Confirm before sending to Distrubution List

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 120
This Year: 1
This Month: 0
This Week: 0
Comments: 40

Sign In
Pick a theme:

# Tuesday, June 27, 2006
Tuesday, June 27, 2006 7:37:27 AM (Mountain Daylight Time, UTC-06:00) ( )

I was concerned about getting emails from people that were sent to large distribution groups and then inadvertantly clicking on 'reply to all' and sending my flame message to everyone in the list. Thus, I scoured the net looking for a 'leg up' on how to bridle the pony we call Outlook.

Here's what I ended up with, largely thanks to Eric Legault's post titled "Getting a Handle on Your Emails with VBA"

Anyway, here's what I wound up with, most of it is a direct rip of Eric's wonderful code.

The only code I wrote is down in objMailItem_Send().

In a nutshell, the code does this.

Minimize the current window displaying the message (an inspector). Enumerate through the list of recipients (aggregate of TO, CC, BCC) and check the type of recipient. If it's a Distribution List, confirm with a message box I want to send, if so, continue to the next item in the collection. If I do not, set the 'cancel' flag to true, and drop out of the list of recipients, because there's no point in continuing to bother me. Finally, if we ended up not sending, restore the message window to something more viewable than minimized.

MAKE SURE TO SIGN YOUR CODE Outlook 2003 (you are using this right?) Has a default macro security level of High. It will not run code unless it smells like safe code.

DO NOT LOWER YOUR SECURITY LEVEL Assign yourself a self-signed certificate using "C:\Program Files\Microsoft Office\OFFICE11\SELFCERT.EXE" and use that to sign your code.

ThisOutlookSession (Outlook intrinsic object)

Option Explicit

Dim myMailItemTrapper As clsMailItemTrapper

Private Sub Application_Startup()
   Set myMailItemTrapper = New clsMailItemTrapper
End Sub

Private Sub Application_Quit()
   Set myMailItemTrapper = Nothing
End Sub

clsMailItemTrapper (Class Module)

Option Explicit

Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objOpenInspector As Outlook.Inspector
Dim WithEvents objMailItem As Outlook.mailItem

Private Sub Class_Initialize()
   Set objInspectors = Application.Inspectors
End Sub

Private Sub Class_Terminate()
   Set objOpenInspector = Nothing
   Set objInspectors = Nothing
   Set objMailItem = Nothing
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
   If Inspector.CurrentItem.Class = olMail Then
      Set objMailItem = Inspector.CurrentItem
      Set objOpenInspector = Inspector
   End If
End Sub

Private Sub objMailItem_Send(Cancel As Boolean)

   Dim r As Recipient
      For Each r In objMailItem.Recipients
         If r.DisplayType = olDistList Then
            objOpenInspector.WindowState = olMinimized
            If (MsgBox("Do you really want to the message to the list: " + r.Name, vbQuestion + vbYesNo, "Verify Send to Group") = vbNo) Then
               Cancel = True
               Exit For
            End If
         End If
      Next r
      If Cancel = False Then
         objOpenInspector.WindowState = olMaximized
      End If
End Sub

Comments [0] | | #