gpt4 book ai didi

python - Exchangelib 库不下载 html 格式的电子邮件正文

转载 作者:太空宇宙 更新时间:2023-11-03 21:02:32 26 4
gpt4 key购买 nike

我已经编写了使用exchangelib库将MS Exchange服务器电子邮件正文下载为html的代码,但它下载了没有<>括号的html内容

import datetime
from exchangelib import ServiceAccount, Account, Configuration, DELEGATE
from exchangelib import EWSDateTime, EWSTimeZone, EWSDate,

server = 'server url'
username = 'username'
password= 'password'
credentials = ServiceAccount(username=username, password=password)
config = Configuration(server=server, credentials=credentials)
account = Account(
primary_smtp_address='xyz@gmail.com',
config=config, credentials=credentials,
autodiscover=False,
access_type=DELEGATE
)

# to fetch 6 days before emails
tz = EWSTimeZone.localzone()
end = tz.localize(EWSDateTime.combine(EWSDate.today(), datetime.time(0)))
start = end - datetime.timedelta(days=6)
for item in account.inbox.filter(datetime_received__range=(start, end)):
emailbody = item.body
with open('test.html', 'w', encoding='utf-8') as fdata:
fdata.write(emailbody)

预期结果:

<html><head>....</head></html>

实际输出:

html head .../head /html

最佳答案

这可能就是从服务器接收正文的方式。如果你enable debug logging ,你可以看到 body 的实际样子。

关于python - Exchangelib 库不下载 html 格式的电子邮件正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55632536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com