Guest User

Untitled

a guest
Feb 22nd, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. From: someone.email@domain.com
  2. Sent: Date, Month...
  3. Cc: more.emails@domian.com
  4. Subject: Awesome Subject
  5.  
  6. Now the body of the email
  7.  
  8. def get_body(msg):
  9. if msg.is_multipart():
  10. return get_body(msg.get_payload(0)).decode(encoding='windows-1252')
  11. else:
  12. return msg.get_payload(None, decode=True).decode(encoding='windows-1252')
  13.  
  14. if email_msg.is_multipart():
  15. for part in email_msg.walk():
  16. part_type = part.get_content_type()
  17. part_dispo = str(part.get('Content-Disposition'))
  18.  
  19. if part_type == 'type/plain' and 'attachment' not in part_dispo:
  20. msg_payload = part.get_payload(decode=True)
  21. msg_payload = msg_payload.decode()
  22. clean_body = get_body(msg_payload)
  23. print(clean_body)
Add Comment
Please, Sign In to add comment