Python Outlook:读取其他邮箱的收件箱

问题描述 投票:2回答:5

我正在使用Outlook 2010 - 并拥有我的主邮箱:[email protected]

我还在我的个人资料中添加了另一个邮箱:mb data proc

两者都显示为Outlook中的顶级文件夹:

[email protected]
-Inbox
-Sent Items
-Deleted Items

mb data proc
-Inbox
-Sent Items
-Deleted Items

我无法为其他邮箱创建不同的配置文件。它已被添加到相同的配置文件中。

如何在“mb data proc”邮箱中获取对收件箱的引用?

这与Get reference to additional Inbox中描述的问题相同,但这在VBS中。

在python中怎么办?

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder=outlook.Folders("mb data proc")
msg=folder.Items
msgs=msg.GetLast()
print msgs    

我试过这个,但是我收到了这个错误:

       folder=outlook.Folders("mb data proc")
AttributeError: _Folders instance has no __call__ method
python outlook inbox
5个回答
2
投票

这是一个简单的解决方案。我认为你错过的唯一部分是到"Inbox"里面的"mb data proc"文件夹。

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder = outlook.Folders("mb data proc")
inbox = folder.Folders("Inbox")
msg = inbox.Items
msgs = msg.GetLast()
print msgs

0
投票

谢谢你的帖子!这是我根据您的输入汇总的功能,以读出可用的文件夹:

这是我的第一篇文章,所以我希望我能正确复制代码:

def check_shared(namespace,recip = None): 
    """Function takes two arguments:
        .) Names-Space: e.g.: 
            which is set in the following way: outlook = Dispatch("Outlook.Application").GetNamespace("MAPI") and
        .) Recipient of an eventual shared account as string: e.g.: Shared e-Mail adress is "[email protected]"
            --> This is optional --> If not added, the standard-e-Mail is read out"""


    if recip is None:
        for i in range(1,100):                           
            try:
                inbox = namespace.GetDefaultFolder(i)     
                print ("%i %s" % (i,inbox))            
            except:
                #print ("%i does not work"%i)
                continue
    else:
        print('The folders from the following shared account will be printed: '+recip)
        tmpRecipient = outlook.CreateRecipient(recip)
        for i in range(1,100):                           
            try:
                inbox = namespace.GetSharedDefaultFolder(tmpRecipient, i)     
                print ("%i %s" % (i,inbox))            
            except:
                #print ("%i does not work"%i)
                continue
    print("Done")

0
投票

如果您在Outlook中查找其他邮箱或单独的PST文件,请尝试使用Store / Stores MAPI对象。

import win32com.client

for stor in win32com.client.Dispatch("Outlook.Application").Session.Stores:
    print( stor.DisplayName) 

PS .Session返回与.GetNamespace(“MAPI”)相同的引用

供参考https://docs.microsoft.com/en-us/office/vba/api/overview/outlook


0
投票

我试图访问其他邮箱并从这些共享文件夹中读取收件箱

导入win32com.client

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

>>> folder = outlook(1)

>>> inbox = folder.Folders("Inbox")

>>> message = inbox.Items

>>> messages = message.GetLast()

>>> body_content = messages.body

>>> print (body_content)

0
投票

我有一个类似的疑问,据我所知,这里说的解决方案是Python 2.7

我将尝试使用Python 3. +版本来理解如何操作它。

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder = outlook.Folders.Item("Mailbox Name")
inbox = folder.Folders.Item("Inbox")
msg = inbox.Items
msgs = msg.GetLast()
print (msgs)
print (msgs.Subject)

由于_Folder不可调用,因此您需要使用Python 3+中的Folders.Item()方法来引用您的邮箱。

希望这很有帮助。谢谢!


-1
投票

首先,您可以使用Namespace.GetSharedDefaultFolder方法。

其次,然后行

folder=outlook.Folders("mb data proc")

需要是

folder=outlook.Folders.Item("mb data proc")

© www.soinside.com 2019 - 2024. All rights reserved.