gpt4 book ai didi

python - 如何使用Python从outlook获取突出显示(选定)的邮件?

转载 作者:太空宇宙 更新时间:2023-11-03 21:19:29 30 4
gpt4 key购买 nike

我不明白如何使用 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)

关于python - 如何使用Python从outlook获取突出显示(选定)的邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54418300/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com