Home > Software design >  Opening outlook with filled fields using Python
Opening outlook with filled fields using Python

Time:08-20

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.

CodePudding user response:

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

CodePudding user response:

mailto would work fine as long as you don't want HTML body or attachments. Something along the lines:

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

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

  • Related