尝试使用Python程序正确标记Outlook联系人

m4pnthwp  于 2023-04-28  发布在  Python
关注(0)|答案(1)|浏览(124)

我写了一个Python程序,它遍历一个联系人文件夹,并为所有当前没有联系人的联系人(有数百个)设置一个后续标志。目前,该程序被设置为覆盖当前的后续标签,但这将改变。添加随访,因为只有提醒框和提醒日期,“任务开始”和“任务到期日”框为空。
这是程序的代码:

import win32com.client
import datetime
import pywintypes

#Connect to Outlook
outlook = win32com.client.Dispatch("Outlook.Application")
namespace = outlook.GetNamespace("MAPI")

#Set up the Contacts folder
contacts_folder = outlook.GetNamespace('MAPI').GetDefaultFolder(10)

#Define yesterday
yesterday = datetime.datetime.now() + datetime.timedelta(days=-1)
yesterday = datetime.datetime.combine(yesterday, datetime.time(9, 0, 0)) # Set the time to 9:00 AM

print("Begin contact list")

#Iterate over the contacts in the folder
for contact in contacts_folder.Items:
    #Determines that contact is marked as a task
    if contact.IsMarkedAsTask is True:
        #Determines if contact was created on 4/27/23 - This If statement should be REMOVED once the program is edited
        if "4/27/23" in contact.Body:
            contact.MarkAsTask(4) #4 = Contact Due with no Date
            contact.ReminderSet = True
            contact.ReminderTime = yesterday
            contact.TaskSubject = "Follow up"
            contact.Save()

print("Contacts printed successfully!")

当我运行代码时,它确实识别了联系人,输入了提醒日期,并且不返回任何错误。然而,我没有看到红色的大多数联系人文件没有进入和手动编辑标志,即使它是在正确的。它甚至似乎将它们添加到提醒列表中,但我没有看到Outlook中的红色。有没有可能在不添加截止日期的情况下显示它,或者这是使条目可靠显示的唯一方法?这可能是outlook的问题,而不是python的问题,因为代码中没有任何错误,而且似乎执行得很好,但我不完全确定。谢谢大家。

fcipmucu

fcipmucu1#

以红色显示项目是由特定视图完成的-单击“视图”功能区上的“视图设置”,然后单击“条件格式”。“列表”视图将具有该设置,“名片”则没有。

相关问题