Opening outlook with filled fields using Python

Viewed 47

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@domain.com', new=1)

Hope u can help me, ty.

2 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@domain.com"  # 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

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:user1@domain.demo?subject=Test%20Subject&body=Test%20body&cc=user2@domain.demo&bcc=user3@domain.demo

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

Related