编辑.msg outlook Python的正文



我正在尝试替换单词"接口";用";测试";在outlook模板(.msg(中。我可以替换正文,但它不编辑模板。msg。目标是看到单词"测试";而不是";接口";当我做template_6x.display((时。模板处于只读模式

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
find_in_email_6 = "Interface"
template_six = outlook.OpenSharedItem(r"\usersEmail 6.msg")
body = template_six.Body
replace_six=body.replace("Interface","test")
if find_in_email_6 in body:
replace_six
print(template_six.Body)#display interface
print(replace_six)#display test
template_six.display()

我终于找到了,必须使用HTMLBody,这里的代码:

template_six = outlook.OpenSharedItem(r"\usersEmail 6.msg")
new_template_six = template_six
body = template_six.HTMLBody
if find_in_email_6 in body:
new_template_six.HTMLBody = body.replace ("Interface","test")
new_template_six.display()

我必须找到如何删除只读之前显示现在:(

使用Application.CreateItemFromTemplate方法,该方法从Outlook模板(.oft(创建新的Microsoft Outlook项目并返回新项目。

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
find_in_email_6 = "Interface"
template_six = outlook.CreateItemFromTemplate(r"\usersEmail 6.msg")
body = template_six.HTMLBody
replace_six=body.replace("Interface","test")
if find_in_email_6 in body:
replace_six
print(template_six.HTMLBody)#display interface
print(replace_six)#display test
template_six.display()

您可以在"如何:基于模板文章创建新的Outlook邮件"中阅读有关该方法的更多信息。

最新更新