Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pentemino

macrumors newbie
Original poster
Jul 16, 2014
1
0
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: http://www.slipstick.com/developer/check-messages-you-send-for-number-of-recipients/.

Here is the code for Windows from the above website:
Code:
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!
 
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!

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.

Code:
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
				else
					-- action for 2nd button goes here
					--send first item of outgoingMessages
				end if
			end if
		end if
	end tell
else
	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
 

Attachments

  • Screen Shot 2014-07-17 at 02.46.22.png
    Screen Shot 2014-07-17 at 02.46.22.png
    65.3 KB · Views: 60
  • Screen Shot 2014-07-17 at 03.03.43.png
    Screen Shot 2014-07-17 at 03.03.43.png
    18.7 KB · Views: 105
  • Screen Shot 2014-07-17 at 03.05.33.png
    Screen Shot 2014-07-17 at 03.05.33.png
    131.5 KB · Views: 72
  • Screen Shot 2014-07-17 at 02.52.56.png
    Screen Shot 2014-07-17 at 02.52.56.png
    454.6 KB · Views: 87
  • Screen Shot 2014-07-17 at 03.18.19.png
    Screen Shot 2014-07-17 at 03.18.19.png
    29.5 KB · Views: 62
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.