python - 如何使用 Python MAPI 从 Outlook 获取 'Recipient' 姓名和电子邮件地址

标签 python outlook automation

就像 .SenderName 为我提供可以轻松附加到列表中的发件人名称一样,他们是否有任何对象可以对我的邮件的“收件人”执行相同的操作。

我尝试过 .Recipients,但一旦添加到列表中,它们就会显示为 COMObjects,无法由 Python 操作。

我想要的只是一个简单的收件人姓名列表。

最佳答案

最简单的方法是

示例

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.Folders["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ebee3bdfccecbe3efe7e2a0ede1e3" rel="noreferrer noopener nofollow">[email protected]</a>"].Folders["Inbox"]


def get_email_address():
    for message in inbox.Items:
        print("========")
        print("Subj: " + message.Subject)
        print("Email Type: ", message.SenderEmailType)
        if message.Class == 43:
            try:
                if message.SenderEmailType == "SMTP":
                    print("Name: ", message.SenderName)
                    print("Email Address: ", message.SenderEmailAddress)
                    print("Date: ", message.ReceivedTime)
                elif message.SenderEmailType == "EX":
                    print("Name: ", message.SenderName)
                    print("Email Address: ", message.Sender.GetExchangeUser(
                                                              ).PrimarySmtpAddress)
                    print("Date: ", message.ReceivedTime)
            except Exception as e:
                print(e)
                continue


if __name__ == '__main__':
    get_email_address()

关于python - 如何使用 Python MAPI 从 Outlook 获取 'Recipient' 姓名和电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62658802/

相关文章:

java - 当在 Eclipse 中运行时,为什么我无法使用 JAR 在 64 位系统上打开 32 位 Outlook...?

php - Microsoft Word 自动化 - 以编程方式删除标题(及其子 indo)

Kubernetes 命名空间 post 和 pre delete 钩子(Hook)

python - 高效的元组列表比较

python - 如何正确对 unicode 数据进行制表

c# - 创建 .ICS 文件,添加到 Outlook

javascript - 电子邮件模板的背景图像在 outlook 任何版本中均不起作用

c# - 需要 google chrome 或 firefox 自动化 c#

python - 如何使用 Python Azure SDK 和 Graph 修补现有应用程序?

python - 使用基准年计算指数