Python 3.x 无法提取Outlook电子邮件中的收件人名称
我正在尝试提取收件人地址,打印时得到以下信息:Python 3.x 无法提取Outlook电子邮件中的收件人名称,python-3.x,win32com,Python 3.x,Win32com,我正在尝试提取收件人地址,打印时得到以下信息: <COMObject <unknown>> 如何获取收件人的姓名或电子邮件地址?我认为“message.recipients”给您带来的是一个,而不是一个特定的收件人。您可以通过将集合中的各个收件人添加到您的列表中来解决此问题 要获取电子邮件地址,如果该地址作为Exchange用户提供给您地址,则可能需要一些额外的导航,以便您可以使用中的函数检索该地址。(通过浏览这些链接中的msdn文档,您可以了解有关某些Outlook对
<COMObject <unknown>>
如何获取收件人的姓名或电子邮件地址?我认为“message.recipients”给您带来的是一个,而不是一个特定的收件人。您可以通过将集合中的各个收件人添加到您的列表中来解决此问题
要获取电子邮件地址,如果该地址作为Exchange用户提供给您地址,则可能需要一些额外的导航,以便您可以使用中的函数检索该地址。(通过浏览这些链接中的msdn文档,您可以了解有关某些Outlook对象的更多信息。)
我在代码中添加了几行代码,下面的代码对我很有用
while message:
subject = message.Subject
sender = message.SenderName
recipients = message.Recipients
subject_list.append(str(subject))
sender_list.append(str(sender))
#This loop will add each recipient from an email's Recipients Collection to your list individually
for r in recipients:
recipients_list.append(r)
i+=1
message = messages.GetPrevious()
if i > 10:
break
for subject in subject_list:
print(subject)
for sender in sender_list:
print(sender)
for recipient in recipients_list:
#Now that the for loop has gone into the Recipient Collection, this should print the recipient name
print(recipient)
#This is the "Address", but for me they all appeared as Exchange Users, rather than explicit email addresses.
print(recipient.Address)
#I used this code to get the actual addresses
print(recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress)
while message:
subject = message.Subject
sender = message.SenderName
recipients = message.Recipients
subject_list.append(str(subject))
sender_list.append(str(sender))
#This loop will add each recipient from an email's Recipients Collection to your list individually
for r in recipients:
recipients_list.append(r)
i+=1
message = messages.GetPrevious()
if i > 10:
break
for subject in subject_list:
print(subject)
for sender in sender_list:
print(sender)
for recipient in recipients_list:
#Now that the for loop has gone into the Recipient Collection, this should print the recipient name
print(recipient)
#This is the "Address", but for me they all appeared as Exchange Users, rather than explicit email addresses.
print(recipient.Address)
#I used this code to get the actual addresses
print(recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress)