当前位置: 首页 » 综合知识 » it知识 » 正文

Python如何读取Outlook的电子邮件

发布时间:2023-07-20 以下文章来源于网友投稿,内容仅供参考!

首先你需要导入 win3.client,为此你需要安装 pywin32:

pip install pywin32

我们需要通过 MAPI 协议连接 Outlok:

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

然后从 outlook 配置中获取所有的账户:

accounts= win3.client.Dispatch("Outlook.Application").Session.Accounts;

在然后需要从名为 emaileri_al 的收件箱中获取邮件:

def emailleri_al(folder):     messages = folder.Items     a=len(messages)     if a>0:         for message2 in messages:              try:                 sender = message2.SenderEmailAddress                 if sender != "":                     print(sender, file=f)              except:                 print("Ben hataym")                 print(account.DeliveryStore.DisplayName)                 pass               try:                 message2.Save                 message2.Close(0)              except:                  pass

你需要进入所有账户的所有收件箱中获取电子邮件:

for account in accounts:     global inbox     inbox = outlook.Folders(account.DeliveryStore.DisplayName)     print("****Account Name**********************************",file=f)     print(account.DisplayName,file=f)     print(account.DisplayName)     print("***************************************************",file=f)     folders = inbox.Folders      for folder in folders:         print("****Folder Name**********************************", file=f)         print(folder, file=f)         print("*************************************************", file=f)         emailleri_al(folder)         a = len(folder.folders)          if a>0 :             global z             z = outlook.Folders(account.DeliveryStore.DisplayName).Folders(folder.name)             x = z.Folders             for y in x:                 emailleri_al(y)                 print("****Folder Name**********************************", file=f)                 print("..."+y.name,file=f)                 print("*************************************************", file=

下面是完整的代码:import win3.client 

import win3 import os import sys  f = open("testfile.txt","w+")  outlook = win3.client.Dispatch("Outlook.Application").GetNamespace("MAPI") accounts= win3.client.Dispatch("Outlook.Application").Session.Accounts;  def emailleri_al(folder):     messages = folder.Items     a=len(messages)     if a>0:         for message2 in messages:              try:                 sender = message2.SenderEmailAddress                 if sender != "":                     print(sender, file=f)              except:                 print("Error")                 print(account.DeliveryStore.DisplayName)                 pass               try:                 message2.Save                 message2.Close(0)              except:                  pass    for account in accounts:     global inbox     inbox = outlook.Folders(account.DeliveryStore.DisplayName)     print("****Account Name**********************************",file=f)     print(account.DisplayName,file=f)     print(account.DisplayName)     print("***************************************************",file=f)     folders = inbox.Folders      for folder in folders:         print("****Folder Name**********************************", file=f)         print(folder, file=f)         print("*************************************************", file=f)         emailleri_al(folder)         a = len(folder.folders)          if a>0 :            &nbs;global z             z = outlook.Folders(account.DeliveryStore.DisplayName).Folders(folder.name)             x = z.Folders             for y in x:                 emailleri_al(y)                 print("****Folder Name**********************************", file=f)                 print("..."+y.name,file=f)                 print("*************************************************", file=f)    print("Finished Succesfully")
  • • Linux Ecdsa密钥长度选择有何依据

    在Linux

  • • Linux Khook在内核监控中的应用如何

    Linux

  • • Linux Gsoap是否支持异步通信

    GSOAP是

  • • Linux Coremail如何提升用户体验

    提升Linu

  • • Linux Ecdsa算法有哪些局限性

    ECDSA

  • 哎呀音乐钢琴键盘学习《 钢琴主人训练营》 西瓜学琴
    郭蝈 陪练钢琴 30节课时 考级刚需 让孩子每一次练琴都是高质量的
    30天轻松学会五线谱 流行钢琴自学初级教程 牙牙学琴
    流行爵士钢琴实战技巧VIP课 - 继伟 哎呀音乐
    【海上钢琴师】原版 MT1990钢琴谱
    百首经典流行钢琴实战曲集 - 继伟
    雷费尔德电钢琴重锤88键专业考级儿童初学者数码电子钢琴家用
    小练咖 真人钢琴陪练 1v1服务 2999随时退 1课时50分钟 考级刚需
    雅马哈电钢琴88键重锤CLP735智能数码电子钢琴家用专业初学者考级
    【原装进口】Yamaha/雅马哈钢琴 b121 SC2原声静音钢琴
  • 珠海专业调钢琴
  • 天津宝坻区调钢琴
  • 天津静海区钢琴调音
  • 成都简阳市钢琴调律
  • 大连瓦房店市钢琴调音
  • 眉山调钢琴联系方式
  • 惠州大亚湾钢琴调琴师
  • 长治调琴师
  • 厦门湖里区钢琴调音师
  • 上海普陀区钢琴调音师