我想重命名我在 Exchange 服务器上收到的某些文件的附件。这可能吗?
我试过的
from exchangelib import ServiceAccount, Configuration, Account, DELEGATE
from exchangelib import FileAttachment
from config import cfg
# Login
credentials = ServiceAccount(username=cfg['imap_user'],
password=cfg['imap_password'])
config = Configuration(server=cfg['imap_server'], credentials=credentials)
account = Account(primary_smtp_address=cfg['smtp_address'], config=config,
autodiscover=False, access_type=DELEGATE)
# Go through all emails, to find the example email
latest_mails = account.inbox.filter()
for msg in latest_mails:
for attachment in msg.attachments:
if attachment.name == 'numbers-test-document.pdf':
print("Rename the example attachment")
# does not work :-( - but no error either
attachment = FileAttachment(name='new-name.pdf',
content=attachment.content)
msg.attachments = [attachment]
msg.save()
print("#" * 80)
我没有收到错误消息。但它也没有重命名。代码执行(我看到Rename the example attachment
了),但它没有执行。如何做到这一点exchangelib
?