Question

I want to use the following python code to automize some reporting

from win32com import client
obj = client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(0x0)
newMail.Subject = "This is the subject"
...
newMail.Body = "This is the text I want to send in the mail body"

But doing it this way deletes the signature. The following code

...
newMail.Body = "This is the text I want to send in the mail body" + newMail.Body

preserves the signature, but destroys the formating. Not acceptable for compliance reasons.

Is there a way to prepend text to the mail body to circumvent the termination of the signatures format?

Was it helpful?

Solution

tmp = newMail.Body.split('<body>')
# split by a known HTML tag with only one occurrence then rejoin
newMail.Body = '<body>'.join([tmp[0],yourString + tmp[1]])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top