[英]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.