Extract body content of a Gmail with Python -


i trying extract body of gmail email. problem able content of email, want body.

import imaplib mail = imaplib.imap4_ssl('imap.gmail.com') mail.login('myusername@gmail.com', 'mypassword') mail.list() # out: list of "folders" aka labels in gmail. mail.select("inbox") # connect inbox. result, data = mail.search(none, "all")  ids = data[0] # data list. id_list = ids.split() # ids space separated string latest_email_id = id_list[-1] # latest  # fetch email body (rfc822) given id result, data = mail.fetch(latest_email_id, "(rfc822)")   raw_email = data[0][1] # here's body, raw text of whole   email # including headers , alternate payloads print raw_email 

the problem code lot of thing don't need. output get:

b'delivered-to: estacionremota1@gmail.com\r\nreceived: 10.157.60.218 smtp id t26csp3600091otf;\r\n sun, 10 sep 2017 10:39:56 -0700 (pdt)\r\nx-received: 10.28.60.4 smtp id

................................................

j4mr2630503wma.46.1505065196879;\r\n sun, 10 sep 2017 10:39:56 -0700 (pdt)\r\narc-seal: i=1; a=rsa-sha256; t=1505065196; cv=none;\r\n d=google.com; s=arc-20160816;\r\n 9:55 -0700 (pdt)\r\nmessage-id: <59b578eb.e2a9df0a.378a2.efff@mx.google.com>\r\ndate: sun, 10 sep 2017 10:39:55 -0700 (pdt)\r\nfrom: myemail@gmail.com\r\n\r\n/camera\r\n'

if has idea fix code grateful. accept new code working. in advance!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -