就像 .SenderName
为我提供可以轻松附加到列表中的发件人名称一样,他们是否有任何对象可以对我的邮件的“收件人”执行相同的操作。
我尝试过 .Recipients
,但一旦添加到列表中,它们就会显示为 COMObjects
,无法由 Python 操作。
我想要的只是一个简单的收件人姓名列表。
最佳答案
最简单的方法是
示例
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.Folders["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ebee3bdfccecbe3efe7e2a0ede1e3" rel="noreferrer noopener nofollow">[email protected]</a>"].Folders["Inbox"]
def get_email_address():
for message in inbox.Items:
print("========")
print("Subj: " + message.Subject)
print("Email Type: ", message.SenderEmailType)
if message.Class == 43:
try:
if message.SenderEmailType == "SMTP":
print("Name: ", message.SenderName)
print("Email Address: ", message.SenderEmailAddress)
print("Date: ", message.ReceivedTime)
elif message.SenderEmailType == "EX":
print("Name: ", message.SenderName)
print("Email Address: ", message.Sender.GetExchangeUser(
).PrimarySmtpAddress)
print("Date: ", message.ReceivedTime)
except Exception as e:
print(e)
continue
if __name__ == '__main__':
get_email_address()
关于python - 如何使用 Python MAPI 从 Outlook 获取 'Recipient' 姓名和电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62658802/