Python 通过 win32com 添加指向 Outlook 任务的超链接
Python adding hyperlink to Outlook task through win32com
我想在通过 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 中创建任务前端,我可以添加超链接。
任务不支持HTML。相反,您必须提供 RTF。
您可以通过 task.RTFBody
(和 task.RTFBody.obj
来方便地查看)调查——但不能设置——给定任务的 RTF。要在任务的 body 中使用 RTF,只需使用 task.Body
属性;将其设置为包含 RTF 的字节数组将自动在 body 中使用该 RTF。具体来说,要得到你想要的body,你可以让
task.Body = rb'{\rtf1{Here is the }{\field{\*\fldinst { HYPERLINK "https://www.python.org" }}{\fldrslt {link}}}{ I need}}'
您也可以试试:
task.HTMLBody = "Here is the <a href='http://www.python.org'>link</a> I need"
这会将 'task.Body' 中的数据覆盖为 'task.HTMLBody'
中提供的 HTML 格式
因此(正文或 HTML正文)最后一个将作为邮件的正文。
我想在通过 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 中创建任务前端,我可以添加超链接。
任务不支持HTML。相反,您必须提供 RTF。
您可以通过 task.RTFBody
(和 task.RTFBody.obj
来方便地查看)调查——但不能设置——给定任务的 RTF。要在任务的 body 中使用 RTF,只需使用 task.Body
属性;将其设置为包含 RTF 的字节数组将自动在 body 中使用该 RTF。具体来说,要得到你想要的body,你可以让
task.Body = rb'{\rtf1{Here is the }{\field{\*\fldinst { HYPERLINK "https://www.python.org" }}{\fldrslt {link}}}{ I need}}'
您也可以试试:
task.HTMLBody = "Here is the <a href='http://www.python.org'>link</a> I need"
这会将 'task.Body' 中的数据覆盖为 'task.HTMLBody'
中提供的 HTML 格式因此(正文或 HTML正文)最后一个将作为邮件的正文。