pytho 读取 outlook pst

引用文件地址https://linux.cn/article-9948-1.html


```python
#coding=utf-8
from win32com.client.gencache import EnsureDispatch as Dispatch

 
 

 
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):
        print("")
        if (hasattr(self.item, 'ReceivedTime')):  
            print('ReceivedTime' + ": " + str(self.item.ReceivedTime))
        if (hasattr(self.item, 'SenderName')):
            print('SenderName' + ": " + self.item.SenderName)
        if (hasattr(self.item, 'Subject')):
            print('Subject' + ": " + self.item.Subject)
        if (hasattr(self.item, 'Body')):
           print('Body' + ": " + self.item.Body)
        if (hasattr(self.item, 'To')):
            print('To' + ": " + self.item.To)
        if (hasattr(self.item, 'CC')):
            print('CC' + ": " + self.item.CC)
 
    def read_mail(self):
        for Account in self.Accounts:
            print(Account.Name)
            
            # 只查找需要的邮箱账号信息
            if Account.Name == 'xxx@xxx.com':
                Folders = Account.Folders
                for Folder in Folders:
                    
                    #只需要收件箱的邮件
                    print(Folder.Name)
                    if Folder.Name == '收件箱':
                        Items = Folder.Items
                        print(len(Items))
                        Items.Sort("[ReceivedTime]", True)
                        count = 1
                        for self.item in Items:
                            print(str(count) + ":")
                            self.parse_mail()
                            print("\n")
                            count += 1
 
 
if __name__ == '__main__':
    mail = Email()
    mail.read_mail()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值