PyMA
PyMA

Reputation: 27

Opening outlook with filled fields using Python

I am trying to create a function to open a new Outlook message, but I would like the message to appear already with the recipient, subject fields. So far what I have found is how to open a new Outlook window with the recipient, but I still can't get the subject to be displayed.

import webbrowser
webbrowser.open('mailto:[email protected]', new=1)

Hope u can help me, ty.

Upvotes: 1

Views: 397

Answers (3)

T Ye
T Ye

Reputation: 1

For using

import win32.com.client as win32
outlook = win32.Dispatch("Outlook.Application")  # Starts Outlook application
... ...

You may need to include the following:

import pythoncom
pythoncom.CoInitialize()

Upvotes: 0

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

mailto would work fine as long as you don't want HTML body or attachments. You can specify to/cc/bbc, subject, and body.

Something along the lines:

mailto:[email protected]?subject=Test%20Subject&body=Test%20body&[email protected]&[email protected]

And it will work under any OS and any email client.

Upvotes: 1

Joseph Julian
Joseph Julian

Reputation: 71

Here is a potential solution using win32.com.client:

import win32.com.client as win32

outlook = win32.Dispatch("Outlook.Application")  # Starts Outlook application
new_email = outlook.CreateItem(0)  # Creates new email item
new_email.To = "[email protected]"  # Add recipients separated by comma or semicolon
new_email.Subject = "How to create new Outlook email in Python"  # Your email subject
new_email.Body = "This text will be the body of your new email"  # Your email body
new_email.Display(True)  # Displays the new email item

Upvotes: 1

Related Questions