Python Outlook:读取附加邮箱的收件箱



我正在使用Outlook 2010 - 并且有我的主邮箱:name@company.com

我还在我的配置文件中添加了另一个邮箱:mb data proc

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

name@company.com
-Inbox
-Sent Items
-Deleted Items
mb data proc
-Inbox
-Sent Items
-Deleted Items

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

如何获取对"mb 数据处理"邮箱中收件箱的引用?

这与此处描述的问题相同 获取对其他收件箱的引用,但这在 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 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+中使用Folder.Item()方法来引用您的邮箱。

希望有帮助。谢谢!

这是一个简单的解决方案。我认为您错过的唯一部分是进入"mb data proc"内部的"Inbox"文件夹。

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

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

导入Win32com.客户端

>>> 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)

如果要在 Outlook 中查找您有权访问的其他邮箱或单独的 PST 文件,请尝试使用存储/存储 MAPI 对象。

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

附言 .会话返回与 相同的引用。GetNamespace("MAPI")

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

谢谢你的帖子!这是我根据您的输入汇总的一个函数,用于读取可用的文件夹:

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

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 "shared@shared.com"
            --> 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")

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

其次,然后是线

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

需要

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

相关内容

最新更新