编程语言
首页 > 编程语言> > Python 操作 Outlook 邮箱

Python 操作 Outlook 邮箱

作者:互联网

#!/usr/bin/env python

-- coding:utf-8 --

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 + '"')

标签:Outlook,inboxmail,Python,namespace,item,win32com,print,邮箱,GetDefaultFolder
来源: https://blog.51cto.com/plking/2491492