简体   繁体   English

如何使用 Python COM 过滤来自某些发件人的电子邮件?

[英]How to use Python COM to filter for emails from certain senders?

I'm trying to automate getting attachments from certain emails and the documentation for win32com.client is horrendous.我正在尝试自动从某些电子邮件中获取附件,并且 win32com.client 的文档非常糟糕。

So far I've got the following:到目前为止,我有以下几点:

import win32com.client as win32
import os

outlook = win32.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.Folders["Payments"].Folders["Inbox"]

messages = inbox.Items


for i in range(10):

    message = messages.GetNext()
    print(message.Sender)
    print(message.Subject)
    print(message.ReceivedTime)
    attachment = message.attachments

    for j in attachment:
        j.SaveAsFile(os.getcwd() + "\\" + j.FileName)

However, I only want to get attachments from say "payments@email.com" which I can't figure out to do.但是,我只想从“payments@email.com”中获取附件,而我不知道该怎么做。

Is there a way to only get the emails and their attachments from certain senders (bonus if I can also filter for the email title)?有没有办法只从某些发件人那里获取电子邮件及其附件(如果我还可以过滤电子邮件标题,则奖励)?

使用诸如filteredItems = Inbox.Items.Restrict("[SenderEmailAddress] = 'payments@email.com' ")的限制文档位于https://docs.microsoft.com/en-us/office/vba/api/ Outlook.items.restrict

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM