python - 使用 Python 访问 Outlook 文件夹时无法收到第一条消息
问题描述
我使用以下内容获取子文件夹的第一条消息
import win32com.client
import os
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in
this case the inbox. You can change that number to reference
messages = inbox.Folders.Item("MyFolder")
message = messages.GetFirst()
虽然它适用于收件箱,但当我尝试获取子文件夹的第一条消息时
我收到一个属性错误:Item.GetFirst raise AttributeError("%s%s" % (self.username , attr))
该文件夹已经有消息
有任何想法吗?
解决方案
我将子文件夹部分更改为
messages = inbox.Folders[3].Items
message = messages.GetLast()
我测试了括号中的数字,发现在我的情况下 [3] 是理想的子文件夹
推荐阅读
- excel - 由于源文件太大,宏运行非常慢
- python - pandas:excel输出中的彩色单元格取决于列值
- asp.net - 如何更改模型类中的 img src?
- java - 条件构建器中的 if 语句
- spring-boot - spring boot 登录检查实现方式
- unity3d - unity3d 检测游戏对象进入主摄像头屏幕并离开
- java - 如何修复:className='com.hazelcast.aws.AwsDiscoveryStrategy', discoveryStrategyFactory=null 是否是策略类名中的拼写错误?
- python - 如何在python3中键入检查一个可选参数最初设置为None的函数?
- excel - 如何推进循环以从 A 列中选择和复制数据?
- postgresql - 如何对无效数字数据的列求和?