首页 > 解决方案 > Python通过win32com向Outlook任务添加超链接

问题描述

我想在通过 win32com 创建的任务正文中创建一个超链接。

到目前为止,这是我的代码:

outlook = win32com.client.Dispatch("Outlook.Application")
outlook_task_item = 3
recipient = "my_email@site.com"
task = outlook.CreateItem(outlook_task_item)
task.Subject = "hello world"
task.Body = "please update the file here"
task.DueDate = dt.datetime.today()
task.ReminderTime = dt.datetime.today()
task.ReminderSet = True
task.Save()

我试图设置属性task.HTMLBody,但出现错误:

AttributeError: Property 'CreateItem.HTMLBody' can not be set.

我也试过

task.Body = "Here is the <a href='http://www.python.org'>link</a> I need"

但我没有得到正确的超链接。

但是,如果我在 Outlook 中创建任务前端,我可以添加超链接。

标签: pythonoutlookwin32com

解决方案


你也可以试试:

task.HTMLBody = "Here is the <a href='http://www.python.org'>link</a> I need"

这会将“task.Body”中的数据覆盖为“task.HTMLBody”中提供的 HTML 格式

所以无论是最后一个(正文或 HTMLBody)都将被视为邮件的正文。


推荐阅读