Python - outlook没有看到今天的电子邮件

问题描述 投票:0回答:1

我正在尝试下载我每天从运输系统收到的文件/报告。

已经写了一些代码(我刚刚开始使用Python,因此它看起来不太专业)但是当我想要获得最新的电子邮件时,程序无法识别它们。

我检查了len(电子邮件),它显示了2552封电子邮件。当我从这个“目录”(2552)转到最新版本时,它是昨天(2019-02-15)的最后一封电子邮件,虽然今天(2019-02-16)我已经收到了附件的电子邮件。

我应该修改我在这里使用的“电子邮件”变量的语法(我想这可能是一个问题,它在某种程度上不包含那里的所有电子邮件)?

真的很感激帮助!

代码如下:

import win32com.client

folder = win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI").GetDefaultFolder(6)

subfolder=folder.Folders(3)

email = subfolder.Items

message = email.Item(2252)

attachment = message.Attachments.Item(1)

attachment.SaveAsFile(r'C:\Users\310295192\Desktop\report.xlsx')
python email outlook attachment email-attachments
1个回答
0
投票

如果您从未对Items集合进行排序,则它将不会按任何特定顺序排序。尝试通过ReceivedTime属性对其进行排序:

email.Sort "ReceivedTime", false
© www.soinside.com 2019 - 2024. All rights reserved.