从WIN32COM [使用Python]从另一个地址读取Outlook电子邮件
我正在尝试使用WIN32COM阅读Outlook地址的电子邮件,但我只能从Local Outlook地址访问这些项目。您知道如何输入其他地址所需的凭据吗? 在我的dispatch()方法中,方法接受用户名参数,但没有密码。
这是我的方法:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application", userName='[email protected]').GetNamespace("MAPI")
for account in outlook.Session.Accounts:
print (account.DisplayName) # [email protected]
print (account.SmtpAddress)
print (account.UserName)
print(account.DeliveryStore.DisplayName)
dir(win32com.client.Dispatch)
help(win32com.client.Dispatch)
print(outlook.Session.Accounts.GetIDsOfNames)
我从控制台的输出:
I'm trying to read emails from outlook address using win32com, but I can only access the items from local outlook address. Do you know how to input the needed credentials for another address?
In my Dispatch() method accepts username parameter but no password.
Here is my approach:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application", userName='[email protected]').GetNamespace("MAPI")
for account in outlook.Session.Accounts:
print (account.DisplayName) # [email protected]
print (account.SmtpAddress)
print (account.UserName)
print(account.DeliveryStore.DisplayName)
dir(win32com.client.Dispatch)
help(win32com.client.Dispatch)
print(outlook.Session.Accounts.GetIDsOfNames)
And my output from the console:
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您 can 使用 .logon 将用户记录到MAPI,获得MAPI会话的方法。使用
登录
方法仅在尚未运行Outlook时登录到特定的配置文件。这是因为只有一个Outlook进程一次可以运行,而Outlook Process仅使用一个配置文件,仅支持一个MAPI会话。当用户第二次启动Outlook时,Outlook的实例在同一Outlook过程中运行,不会创建新的过程,并且使用相同的配置文件。另外,您可能会发现返回代表Exchange全局地址列表的
addressList
对象的方法有帮助。getGlobalAddresslist
仅支持交换服务器。如果没有可用或找不到全局地址列表,它将返回错误。您可以使用返回
存储
集合对象,该对象表示当前配置文件中的所有存储对象。配置文件定义一个或多个电子邮件帐户,每个电子邮件帐户都与特定类型的服务器关联。对于Exchange服务器,可以在服务器,Exchange Public文件夹中或本地个人文件夹文件(.pst)或离线文件夹文件(.ost)中存储。对于POP3,IMAP或HTTP电子邮件服务器,商店是.pst文件。使用商店
和存储
对象列举当前会话中所有商店的所有文件夹和搜索文件夹。如果您需要获取未在Outlook中配置的帐户,而是共享帐户。 nofollow noreferrer“> namespace.getSharedDefaultFolder代码>文件夹代表指定用户指定的默认文件夹的对象。此方法用于委派方案,其中一个用户已将其一个或多个默认文件夹授予另一个用户访问(例如,他们的共享
galendar
文件夹)。You can use the NameSpace.Logon method which logs the user on to MAPI, obtaining a MAPI session. Use the
Logon
method only to log on to a specific profile when Outlook is not already running. This is because only one Outlook process can run at a time, and that Outlook process uses only one profile and supports only one MAPI session. When users start Outlook a second time, that instance of Outlook runs within the same Outlook process, does not create a new process, and uses the same profile.Also you may find the NameSpace.GetGlobalAddressList method helpful which returns an
AddressList
object that represents the Exchange Global Address List.GetGlobalAddressList
supports only Exchange servers. It returns an error if the Global Address List is not available or cannot be found.You can use the NameSpace.Stores property which returns a
Stores
collection object that represents all the Store objects in the current profile. A profile defines one or more email accounts, and each email account is associated with a server of a specific type. For an Exchange server, a store can be on the server, in an Exchange Public folder, or in a local Personal Folders File (.pst) or Offline Folder File (.ost). For a POP3, IMAP, or HTTP email server, a store is a .pst file. Use theStores
andStore
objects to enumerate all folders and search folders on all stores in the current session.If you need to get accounts not configured in Outlook, but shared ones. The NameSpace.GetSharedDefaultFolder method returns a
Folder
object that represents the specified default folder for the specified user. This method is used in a delegation scenario, where one user has delegated access to another user for one or more of their default folders (for example, their sharedCalendar
folder).如果您有权打开其他用户的邮箱/文件夹,则可以使用
namespace.getSharedDefaultFolder(收件人,OlfolderInbox)
(其中code> coced> CODECENT
可以使用创建
对象namespace.CreateCipient )。如果您需要整个邮箱,而不仅仅是默认文件夹之一,则应自动将邮箱添加到当前配置文件中的商店列表中(Outlook自动添加了基于AutoDodiscover XML中的信息,请添加当前用户可访问的委托商店)或在“交换帐户设置”对话框中手动(高级|打开这些额外的邮箱)。在这种情况下,
namespace.stores
集合将包含当前会话中可见的所有邮箱,您将能够以store.getRootfolder()
开始访问所有文件夹。如果商店不在列表中,则可以尝试使用 selfemption (我是它的作者) - 它公开 rdosession 。If you have the right to open the other user's mailbox/folders, you can use
Namespace.GetSharedDefaultFolder(Recipient, olFolderInbox)
(whereRecipient
object can be created usingNamespace.CreateRecipient
).If you need the entire mailbox, not just one of the default folders, the mailbox should be added to the list of stores in the current profile either automatically (Outlook automatically adds accessible delegate stores available to the current user based on the information in autodiscover XML) or manually in the Exchange account setting dialog (Advanced | Open these additional mailboxes). In that case,
Namespace.Stores
collection will contain all mailboxes visible in the current session and you will be able to access all folder starting with theStore.GetRootFolder()
. If the store is not in the list, you can try to use Redemption (I am its author) - it exposes RDOSession.GetSharedMailbox
method.