首页 > 解决方案 > Python win32com:设置电子邮件标题

问题描述

我有一个问题要使用库 win32com 在 python 中写入电子邮件标题。但我不确定这是否可能。

我们可以使用以下方式读取电子邮件标题:

import win32com.client
outlook =win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox=outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
mess=message.Body
internet_header = message.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F")
print(internet_header)

但我不知道我们是否可以使用类似的方法设置电子邮件标题。使用类似的东西不起作用:

new_mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F", internet_header)

任何想法?

谢谢

标签: pythonpython-3.xoutlookpywin32win32com

解决方案


要在外发电子邮件上设置 MIME 标头,请在 PS_INTERNET_HEADERS 命名空间中设置命名属性:

 message.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-My-Header", "some value")

推荐阅读