Guest User

Untitled

a guest
Dec 25th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import imaplib
  2. import smtplib
  3. import email
  4.  
  5. mail=imaplib.IMAP4_SSL("imap.gmail.com")
  6.  
  7. mail.login("**************@gmail.com","********")
  8.  
  9. mail.select('inbox')
  10.  
  11. type,data=mail.search(None,'ALL')
  12.  
  13. mail_ids=data[0]
  14.  
  15. id_list=mail_ids.split()
  16.  
  17. for i in range(int(id_list[-1]),int(id_list[0])-1,-1):
  18.  
  19. typ,data=mail.fetch(i,'(RFC822)')
  20. for response_part in data :
  21. if isinstance(response_part,tuple):
  22. msg=email.message_from_string(response_part[1])
  23. email_from=msg['from']
  24. email_subj=msg['subject']
  25. c=msg.get_payload(0)
  26. print email_from
  27. print "subj:",email_subj
  28. print c
  29.  
  30. Bharath Joshi <bharathjoshi99@gmail.com>
  31. subj: hehe
  32. From nobody Tue Dec 25 15:48:52 2018
  33. Content-Type: text/plain; charset="UTF-8"
  34.  
  35. hello444444444
  36.  
  37. Bharath Joshi <bharathjoshi99@gmail.com>
  38. subj:
  39. From nobody Tue Dec 25 15:48:52 2018
  40. Content-Type: text/plain; charset="UTF-8"
  41.  
  42. 33333
  43.  
  44. Bharath Joshi <bharathjoshi00@gmail.com>
  45. subj:
  46. From nobody Tue Dec 25 15:48:53 2018
  47. Content-Type: text/plain; charset="UTF-8"
  48.  
  49. hello--22
Add Comment
Please, Sign In to add comment