[英]Python styled dataframe to email using win32com outlook
[英]Using Python to access outlook with win32com
我正在努力使用 win32com.client 將 python 與 outlook 集成。
我要做的就是從 outlook 獲取最新的 email 並(目前)檢索並打印附件的名稱
我嘗試使用的代碼:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespcae("MAPI")
inbox = outlook.GetDefaultFolder(6)
message = inbox.GetLast()
att = message.Attachmets
print (att.filename)
Output
com_error: (-2147221005, 'Invalid class string', None, None)
任何幫助將不勝感激。
錯誤是 Outlook 在系統上找不到,但您也拼錯了GetNamespace
,您有GetNamespcae
inbox.GetLast()
更改為messages = inbox.Items
然后message = messages.GetLast()
例子
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
messages.Sort('[ReceivedTime]', False)
message = messages.GetLast()
for attachment in message.Attachments:
print(attachment.FileName)
這是過濾器https://stackoverflow.com/a/57931132/4539709的另一個示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.