![](/img/trans.png)
[英]How to get date & time of received outlook mail and check body from particular sender using python
[英]How to get highlighted (selected) mail from outlook using Python?
我不明白如何使用 Python 解析 Outlook 中突出顯示(選定)的郵件?
我有這個代碼,但它適用於最后一封郵件。
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
message = messages.GetLast()
body_content = message.body
print (body_content)
需要解析突出顯示郵件的發件人電子郵件地址嗎?
應該
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application")
messages = outlook.ActiveExplorer().Selection
message = messages(1)
try:
if message.SenderEmailType == "EX":
print("EX: ", message.Sender.GetExchangeUser().PrimarySmtpAddress)
else:
if message.SenderEmailType == "SMTP":
print("SMTP: ", message.SenderEmailAddress)
except Exception as e:
print(e)
使用Application.ActiveExplorer.Selection.Item(1)
檢索當前選擇的消息。 您的代碼檢索收件箱中的最后一封電子郵件 - 無論“最后一封”是什么,因為您從未明確對項目集合進行排序。 您很可能會收到收件箱中最舊的電子郵件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.