使用 python 和 win32com 阅读 outlook 电子邮件时身份验证的工作原理

How authentication works while reading outlook emails with python and win32com

我了解到我们可以使用以下代码(Reading e-mails from Outlook with Python through MAPI) 从 outlook 读取电子邮件。

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. You can change that number to reference
                                    # any other folder
messages = inbox.Items
message = messages.GetLast()
body_content = message.body
print body_content

但是我们没有在上面的代码中的任何地方提供用户名和密码。 那么代码是如何验证outlook账号的呢

谁能解释一下这里是如何进行身份验证的。

win32com.client 正在与 Outlook COM object. Since Outlook is a singleton 交互,您实际上是在生成 Outlook 的 "hidden" 实例。请记住,每次登录 Outlook 时都不需要输入用户名和密码。这就是为什么此处也不需要用户名和密码的原因。

另外,只要打开了Outlook的COM对象,就无法通过"exlporer"打开Outlook。这是因为只允许一个 Outlook 实例。您可能会注意到,虽然您从未打开 Outlook 的 GUI,但您仍然会收到新电子邮件的弹出消息。