Python script unable to connect to the Microsoft Outlook Version 1.2023.1020.100 (Production) with co pilot.

Sim, Edwin 5 Reputation points
2023-10-26T10:41:18.0266667+00:00

I have this piece of example code below to create email template using python. It work in the old outlook version but throw an error (image below) with the new outlook version. If anyone has encountered a similar issue or knows of a solution :)

 

 

import win32com.client

from win32com.client import Dispatch, constants

 

const=win32com.client.constants

olMailItem = 0x0

obj = win32com.client.Dispatch("Outlook.Application")

newMail = obj.CreateItem(olMailItem)

newMail.Subject = "Subject Subject!!"

newMail.BodyFormat = 2 # olFormatHTML

newMail.HTMLBody = "<HTML><BODY>Enter the <span style='color:red'>message</span> text here.</BODY></HTML>"

newMail.To = "******@test.com"

newMail.display()

Attached image - No description set

Microsoft 365 and Office | Development | Other
Outlook | Windows | Classic Outlook for Windows | For business
{count} vote

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.