Python 操作 Outlook 邮箱

#!/usr/bin/env python

import datetime
import win32com.client
import win32com.client as win32

namespace = win32com.client.Dispatch(‘Outlook.Application‘).GetNamespace(‘MAPI‘)

def folderlist():
for i in range(50):
try:
print(i,namespace.GetDefaultFolder(i).Name)
except:
pass

if name == ‘main‘:
#打印所有邮箱组
folderlist()
folderinbox = namespace.GetDefaultFolder(6).Name# 6-indox,3-delete,4-outbox,5-sent,
print(folderinbox)

inboxmail = namespace.GetDefaultFolder(6)

#打印内容
#c01 = inboxmail.Items.Find(r"[Subject]=‘MDB Technical Weekly Meeting‘")
#c02 = c01.Body
#print(c02)

#时间过滤
i = inboxmail.Items.Restrict(r"[LastModificationTime] > ‘28/4/2020‘")
print("inbox:",i.Count)

#内容过滤
for item in i:
    if "Done" in item.Body:
        print("邮件主题是: " + ‘"‘ + item.Subject + ‘"‘)

相关推荐