# Import the email modules we'll needfrom email.parser import BytesParser, Parserfrom email.policy import default# If the e-mail headers are in a file, uncomment these two lines:# with open(messagefile, 'rb') as fp:# headers = BytesParser(policy=default).parse(fp)# Or for parsing headers in a string (this is an uncommon operation), use:headers = Parser(policy=default).parsestr('From: Foo Bar <user@example.com>\n''To: <someone_else@example.com>\n''Subject: Test message\n''\n''Body would go here\n')# Now the header items can be accessed as a dictionary:print('To: {}'.format(headers['to']))print('From: {}'.format(headers['from']))print('Subject: {}'.format(headers['subject']))# You can also access the parts of the addresses:print('Recipient username: {}'.format(headers['to'].addresses[0].username))print('Sender name: {}'.format(headers['from'].addresses[0].display_name))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。