Opening outlook with filled fields using Python

Question:

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.

Asked By: PyMA

||

Answers:

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
Answered By: Joseph Julian

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.

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.