繁体   English   中英

Python 通过循环将 outlook 颜色类别添加到特定电子邮件

[英]Python adding outlook color categories to specific emails with a loop

I am trying to add color categories to existing emails in a given outlook folder based on criterias such as email object and/or sender email address.

import win32com.client as client
import win32com
import pandas as pd

outlook = client.Dispatch("Outlook.Application").GetNamespace('MAPI')

main_account = outlook.Folders.Item(1)
second_account = outlook.Folders.Items(3)

df = pd.read_excel (r'C:\Python\test.xls')

df_outlook_folder = df['Outlook_folder'].tolist()
df_mail_object = df['Mail_object'].tolist()

out_iter_folder = main_account.Folders['Inbox'].Folders['TEST']

fixed_item_count = out_iter_folder.Items.Count
item_count = out_iter_folder.Items.Count

if yout_iter_folder.Items.Count > 0:
    for i in reversed(range(0,item_count)):
        message = out_iter_folder.Items[i]
        for y,z in zip(df_mail_object,df_outlook_folder):
            try:
                if y in message.Subject:
                     message.Move(second_account.Folders['Inbox'].Folders['TESTED'].Folders[z]
            except:
                pass
item_count = out_iter_folder.Items.Count
print('Nb mails sorted:',fixed_item_count - item_count)

上面的代码使我能够根据邮件 object 移动电子邮件,但到目前为止我无法添加一个功能来更改 outlook 颜色类别

到目前为止,我花了一些时间在以下文档上但没有成功https://docs.microsoft.com/en-us/office/vba/api/outlook.categories

类别是已分配给 Outlook 项目的类别名称的分隔字符串。

mail.Categories='Red category'
mail.Save()

您可能会发现使用 python 线程的电子邮件中的更新类别很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM