我想使用以下python代码自动化一些报告
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"
但这样做会删除签名。以下代码
...
newMail.Body = "This is the text I want to send in the mail body" + newMail.Body
保留签名,但会破坏格式化。由于合规原因,这是不可接受的。
有没有办法在邮件正文中添加文本以规避签名格式的终止?
答案 0 :(得分:1)
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]])