我設法獲得了 GopiKrishna 發布的以下代碼。它對我有用,但它只會將第一封電子郵件保存在我的 Outlook 中。
我只是想知道對代碼的細微調整是否有助于將所有 Outlook 電子郵件保存在收件箱和/或其他檔案夾中。
from win32com.client import Dispatch
import os
import re
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
print(inbox)
messages = inbox.items
message = messages.GetLast()
name = str(message.subject)
#to eliminate any special charecters in the name
name = re.sub('[^A-Za-z0-9] ', '', name) '.msg'
#to save in the current working directory
message.SaveAs(os.getcwd() '//' name)
uj5u.com熱心網友回復:
您將需要運行 for 回圈
例子
from win32com.client import Dispatch
import os
import re
def save_emails():
for message in inbox.Items:
if message.Class == 43:
name = str(message.Subject)
# to eliminate any special characters in the name
name = re.sub('[^A-Za-z0-9] ', '', name) '.msg'
# to save in the current working directory
message.SaveAs(os.getcwd() '//' name)
if __name__ == '__main__':
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
save_emails()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/472947.html
上一篇:Vue3使用插槽時的父子組件傳值