将电子邮件解析为 Python 可读形式
感谢这里的几位用户,我现在能够通过 IMAP 连接到服务器并下载所有未读消息。然而,问题在于消息不是可读的形式。我是否需要找出一种在应用程序中呈现 HTML 的方法?
这是我的代码:
import imaplib
server = imaplib.IMAP4_SSL('imap.gmail.com')
server.login('USER', 'PASS')
server.select('INBOX')
resp, items = server.search(None, "(UNSEEN)")
for mail in items[0].split():
resp, data = server.fetch(mail, '(RFC822)')
body = data[0][1]
print body
Thanks to several users on here, I now am able to connect to the server via IMAP and download all of the unread messages. The problem, however, is that themessages are not in a readable form. Do I need to figure out a way to render the HTML in my application?
Here is my code:
import imaplib
server = imaplib.IMAP4_SSL('imap.gmail.com')
server.login('USER', 'PASS')
server.select('INBOX')
resp, items = server.search(None, "(UNSEEN)")
for mail in items[0].split():
resp, data = server.fetch(mail, '(RFC822)')
body = data[0][1]
print body
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看
email
模块。它可以帮助您从邮件正文中提取所需的数据。Have a look at the
email
module. It can help you extract the data you want from the message body.