如何使用exchangelib获取非收件箱文件夹的邮件

时间:2018-02-07 04:19:16

标签: python email exchangelib

我想收到非收件箱文件夹的邮件 - 我该怎么做?

我可以像这样获取收件箱文件夹的电子邮件:

hahaha
heiheihei
pupupu
bibibib
........

,并提供:

from exchangelib.folders import Messages

for f in account.folders[Messages]:
    print f

Messages (aaa)
Messages (bbb)
Messages (ccc)

当我拿到我的文件夹时:

ccc

如何使用Python从<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewbox="0 0 100 100"> <path class="grey" d="M40,90 A40,40 0 1,1 60,90" style="fill:none;"/> <path [ngStyle]="{'stroke-dashoffset':percentPath}" class="blue" d="M40,90 A40,40 0 1,1 60,90" style="fill:none;"/> </svg> 文件夹中获取电子邮件?

2 个答案:

答案 0 :(得分:2)

查看最新版exchangelib中的文件夹导航选项:https://github.com/ecederstrand/exchangelib#folders

您可以打印整个文件夹结构:

print(account.root.tree())

然后使用与pathlib相同的语法导航到特定文件夹:

some_other_folder = account.inbox / 'some_inbox_subfolder'
# Or:
some_other_folder = account.root / 'some' / 'other' / 'path'
for item in some_other_folder.all().order_by('-datetime_received')[:100]:
    print(item.subject)

答案 1 :(得分:0)

您只能对收件箱子文件夹执行以下操作:

for subfolder in account.inbox.children:
    for emailz in subfolder.all().only('subject','attachments','datetime_sent').order_by('-datetime_received'):
        #do your thing

或所有根子文件夹:

for subfolder in account.root.children:
    for emailz in subfolder.all().only('subject','attachments','datetime_sent').order_by('-datetime_received'):
        #do your thing