from win32com.client.gencache import EnsureDispatch as Dispatch
import Debug
debug_print=Debug.print_debug_info
class Email(object):
def __init__(self):
self.outlook = Dispatch("Outlook.Application")
self.mapi = self.outlook.GetNamespace("MAPI")
self.Accounts = self.mapi.Folders
self.item = []
def parse_mail(self):
debug_print("")
if (hasattr(self.item, 'ReceivedTime')):
debug_print('ReceivedTime' + ": " + str(self.item.ReceivedTime))
if (hasattr(self.item, 'SenderName')):
debug_print('SenderName' + ": " + self.item.SenderName)
if (hasattr(self.item, 'Subject')):
debug_print('Subject' + ": " + self.item.Subject)
if (hasattr(self.item, 'Body')):
debug_print('Body' + ": " + self.item.Body)
if (hasattr(self.item, 'To')):
debug_print('To' + ": " + self.item.To)
if (hasattr(self.item, 'CC')):
debug_print('CC' + ": " + self.item.CC)
def read_mail(self):
for Account in self.Accounts:
debug_print(Account.Name)
# 只查找需要的邮箱账号信息
if Account.Name == 'xxx@xxx.com':
Folders = Account.Folders
for Folder in Folders:
#只需要收件箱的邮件
debug_print(Folder.Name)
if Folder.Name == '收件箱':
Items = Folder.Items
debug_print(len(Items))
Items.Sort("[ReceivedTime]", True)
count = 1
for self.item in Items:
Debug.print_debug_info(str(count) + ":")
self.parse_mail()
Debug.print_debug_info("\n")
count += 1
if __name__ == '__main__':
mail = Email()
mail.read_mail()
Python 读取outlook本地邮箱各目录实现
最新推荐文章于 2023-12-28 23:16:10 发布