背景:如果某个人给你发了很多垃圾邮件,又没有读;用以下代码可以实现删除所有来自己这个人的邮件邮件,
#python3.68
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
# Select main Inbox
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
# Delete all unread messages from a specific sender
sender = 'yjfw.zx@axxx.com'
try:
for message in messages:
try:
s = message.sender
s = str(s)
if s == sender:
message.Delete()
except:
pass
except:
pass