Scripting Office Outlook 2016 on Mac

Sylvain picture Sylvain · Feb 13, 2016 · Viewed 20.3k times · Source

I'd like to automate Outlook 2016 on Mac.

The task I'd like to automate is basically the following:

  • search inbox for mails from the previous week having a specific pattern in the title
  • prepare a new mail which content is the consolidated content of all the mails found in the previous step
  • let the mail open (or in draft) to let me edit it before to send it

Well, I just don't know how to handle it...

  • Visual Basic (my preferred option) seems not to be present at all in Outlook 2016 on Mac!! I can't even find the VB editor (while I do find it for e.g. excel).
  • AppleScript might allow to do that. But I just do not find any documentation on the outlook API. Plus, it seems to only allow very basic automation.
  • Automator?

Note that I have access to a windows machine. So, it is possible (though painful) for me to write a VBA script there and "transfer it" to the Mac. I do not have Office 365.

Thanks for your help!

Sylvain

Answer

Steve Poole picture Steve Poole · Feb 18, 2016

This is very possible with AppleScript. Here's an example with the basics:

tell application "Microsoft Outlook"

    set theContent to ""
    set theMessages to messages of folder "Inbox" of default account
    repeat with theMessage in theMessages
        if subject of theMessage contains "match this string" then
            set theContent to theContent & plain text content of theMessage
        end if
    end repeat

    set theMessage to make new outgoing message with properties {subject:"the subject line", plain text content:theContent}
    make new recipient with properties {email address:{address:"[email protected]", name:"Lumpkin Skinbark"}} at end of to recipients of theMessage
    open theMessage -- for further editing

end tell

If you haven't found it yet, you can open Outlook's script dictionary by choosing "Open Dictionary" from the File menu and selecting the Microsoft Outlook application.