[英]Using Python to read all emails from Outlook Folder
我想從 Outlook 的特定文件夾中讀取所有電子郵件,但由於某種原因,我只能獲得 1 年的數據。 如果我今天運行它,我會收到從 20 年 12 月 4 日到 19 年 12 月 4 日的所有電子郵件。
我在迭代中做錯了嗎?
import win32com.client
# create object
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
# get the folder
root_folder = outlook.Folders['myemail@xxxxx.com'].Folders['Folder']
messages = root_folder.Items
subject_content = []
body_content = []
creation_time = []
for message in messages:
subject_content.append(message.subject)
body_content.append(message.body)
creation_time.append(message.creationtime)
message = messages.GetNext()
在聯機配置文件中,Exchange 服務器將同時打開的消息數限制為 255。為避免用完 RPC 通道,請在完成項目后立即釋放它們並避免使用“foreach”迭代器 - 它們保持所有訪問的 object 引用直到迭代器被釋放。 改用“for”循環( for index in range(1, messages.Count+1)
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.