简体   繁体   English

如何使用python脚本访问outlook中特定发件人的最新邮件

[英]How to access latest mail from a specific sender in outlook using python script

Using the following code, I am able to access the latest mail from outlook. 使用以下代码,我可以从outlook访问最新的邮件。 But I want to access the latest mail from a particular sender. 但我想访问特定发件人的最新邮件。

import win32com.client

win32com

inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. messages = inbox.Items
message = messages.GetLast()
body_content = message.body
print body_content

I have seen the following code to get the sender's address. 我看到以下代码来获取发件人的地址。 But I am unable to get the latest mail from that address using Getlast() 但我无法使用Getlast()从该地址获取最新邮件

for m in messages:
   if m.SenderEmailAddress == 'some_sender@somewhere.com':
       print(m)

The items in a folder are not stored in any particular order until you call Items.Sort . 在您调用Items.Sort之前,文件夹中的项目不会以任何特定顺序存储。 Sort the items by the ReceivedTime property, then use Items.Find to search on the SenderEmailAddress property. ReceivedTime属性对项目进行排序,然后使用Items.Find搜索SenderEmailAddress属性。

我尝试了很多,最后得到了这个。它将无法使用发件人地址,而是使用发件人名称。

for m in messages: if m.SenderName == 'some_sender_name': print(m)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用python获取收到的Outlook邮件的日期和时间并检查来自特定发件人的正文 - How to get date & time of received outlook mail and check body from particular sender using python 如何使用 Python 保存来自特定发件人和日期的 MS Outlook 附件 - How to save MS Outlook attachments from specific sender and date using Python Python CGI脚本:邮件发件人 - Python CGI script: Mail Sender 是否可以使用 python 对来自特定发件人的 Outlook 收件箱中的所有电子邮件进行排序? - Is it possible to sort through all emails in Outlook inbox from a specific sender using python? 如何使用 Python 从 Outlook 中突出显示(选定)邮件? - How to get highlighted (selected) mail from outlook using Python? 如何使用 Python 从 Outlook 帐户发送带有附件的邮件 - how to Send mail with attachment from your outlook account using Python Outlook 发件人邮件问题 - Outlook Sender mail issue 如何使用 Pywin32 访问 Outlook 中的电子邮件发件人 - How to access emails sender in Outlook using Pywin32 如何使用 Z23EEEB4347BDD255DFC6B7EE9A3 从 outlook 中的 MailItem 获取发件人 SMTP email 地址? - How to get sender SMTP email address from MailItem in outlook using python? 如何通过python从特定发件人中删除电子邮件 - How to delete emails from specific sender by python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM