Office 2011 - Script to check the number of recipients and give an alert

Discussion in 'Mac Apps and Mac App Store' started by pentemino, Jul 16, 2014.

  1. pentemino macrumors newbie

    Jul 16, 2014
    Hello everyone,
    This is my first post on MacRumors! I hope you can all bear with any downfalls I might have in the "forum writing" department...I am the owner of a Macbook with Office 2011 installed. This post is with regards to Outlook 2011.

    Yesterday I sent an email to 180+ ppl and I mistakenly put them in CC rather than BCC, thus revealing all of their email...and at the same time getting insulted from all angles...oops...

    To avoid such a thing from happening again, I have been trying to learn (in the last 4hrs) about AppleScript writing...but I have been going nowhere.

    I am looking to have a script that will pop-up an alert message BEFORE sending the email if the TOTAL number of recipients (regardless of whether in the TO, CC or BCC field) is over a certain number (let's say 20). The message box should of course give me the option to check again the message or send it as it is.

    I have found such a solution for a macro (something I have a little bit more experience on), but I cannot seem to adapt it to the Mac world. Here is the link:

    Here is the code for Windows from the above website:
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
      Dim intRes As Integer
      Dim strMsg As String
      If Item.Recipients.Count > 1 Then
        strMsg = "Your message " & Chr(34) & Item.Subject & Chr(34) & _
                 " contains " & Item.Recipients.Count & " recipients. " & vbCrLf & vbCrLf & _
                 "Do you want to send this message?"
        intRes = MsgBox(strMsg, vbYesNo + vbExclamation, "Confirm Message Send")
        If intRes = vbNo Then
          ' cancel send
          Cancel = True
        End If
      End If
    End Sub
    Would anyone be able to help me? I am freaking out just thinking of the next email I will have to send to all of our clients next week!! :(

    Thank you all in advance!
  2. kryten2 macrumors 6502a

    Mar 17, 2012
    Unfortunately there is no support for VBA in Outlook for Office 2011. However here's an example in AppleScript to get you going. I don't use Outlook so that's why there is no account visible in the screenshot. You also need to uncomment the send statement.

    if application "Microsoft Outlook" is running then
    	tell application "Microsoft Outlook"
    		-- insert actions here
    		set outlookIconPath to path to resource "Outlook.icns"
    		set outgoingMessages to every outgoing message
    		if outgoingMessages is not {} then
    			set allRecipientsCount to count of every recipient of first item of outgoingMessages
    			set messageSubject to subject of first item of outgoingMessages
    			if allRecipientsCount > 1 then
    				set buttonReturned to button returned of (display dialog "Your message " & messageSubject & " contains " & allRecipientsCount & " recipients." & return & "Do you want to send this message?" with title "Send outgoing message?" with icon outlookIconPath buttons {"Don't Send", "Send"} default button 1)
    				if buttonReturned is "Don't Send" then
    					-- action for 1st button goes here
    					display dialog "Check the number of recipients." with icon stop buttons {"OK"} default button 1 giving up after 5
    					-- action for 2nd button goes here
    					--send first item of outgoingMessages
    				end if
    			end if
    		end if
    	end tell
    	display alert "Application Microsoft Outlook is not running!" message "Please launch application Microsoft Outlook before running this script." as critical buttons {"OK"} default button 1 giving up after 5
    end if
    Note : OutgoingMessages is a list. As you can see in my example screenshots I have only one outgoing message hence the use of first item of outgoingMessages to get the first item from the list. If you have many outgoing messages you need to use a repeat loop. Copy the script to your User Scripts Folder. I've named mine OutlookCountRecipients in the example. You need to enable Show Scripts menu in the menu bar in Applescript Editor-->Prefrences

    Attached Files:

Share This Page