Python 从 IMAP 帐户的消息中提取纯文本正文
我一直在研究这个问题,但没有达到目标。
我可以通过 imaplib 连接并获取邮件。
msrv = imaplib.IMAP4(server)
msrv.login(username,password)
# Get mail
msrv.select()
#msrv.search(None, 'ALL')
typ, data = msrv.search(None, 'ALL')
# iterate through messages
for num in data[0].split():
typ, msg_itm = msrv.fetch(num, '(RFC822)')
print msg_itm
print num
但我需要做的是以纯文本形式获取消息正文,我认为这适用于电子邮件解析器,但我在使其工作时遇到问题。
有人有完整的例子我可以看一下吗?
谢谢,
I have been working on this and am missing the mark.
I am able to connect and get the mail via imaplib.
msrv = imaplib.IMAP4(server)
msrv.login(username,password)
# Get mail
msrv.select()
#msrv.search(None, 'ALL')
typ, data = msrv.search(None, 'ALL')
# iterate through messages
for num in data[0].split():
typ, msg_itm = msrv.fetch(num, '(RFC822)')
print msg_itm
print num
But what I need to do is get the body of the message as plain text and I think that works with the email parser but I am having problems getting it working.
Does anyone have a complete example I can look at?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了获取电子邮件正文的纯文本版本,我做了这样的事情......
To get the plain text version of the body of the email I did something like this....
这是 docs 中的一个最小示例:
在本例中, data[ 0][1]包含消息正文。
Here is a minimal example from the docs:
In this case, data[0][1] contains the message body.