Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate Outlook on Mac with Python

I can automate Outlook on windows with win32/COM, but does anyone know of a pure python way to do the same on mac osx?

A simple use case would be:

  • Open outlook/connect to the active instance
  • Launch a blank new email

I want to create an app to create email templates and attach files, then let the user finish editing the email and send when ready, NOT just send emails.

Is there a python wrapper for applescript that may work? (I don't know anything about applescript, so an example would help).

like image 364
Jayme Gordon Avatar asked Mar 02 '23 12:03

Jayme Gordon


1 Answers

Figured it out using py-appscript

pip install appscript
from appscript import app, k

outlook = app('Microsoft Outlook')

msg = outlook.make(
    new=k.outgoing_message,
    with_properties={
        k.subject: 'Test Email',
        k.plain_text_content: 'Test email body'})

msg.make(
    new=k.recipient,
    with_properties={
        k.email_address: {
            k.name: 'Fake Person',
            k.address: '[email protected]'}})

msg.open()
msg.activate()

Also very useful to download py-appscript's ASDictionary and ASTranslate tools to convert examples of AppleScript to the python version.

like image 167
Jayme Gordon Avatar answered Mar 06 '23 09:03

Jayme Gordon