SHARE
TWEET

Untitled

a guest Feb 17th, 2019 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import imaplib
  4. import os
  5. import sys
  6.  
  7. source_imap_host     = 'mail.aa.net.uk'
  8. source_imap_username = 'user@domain'
  9. source_imap_password = 'password'
  10.  
  11. source_imap = imaplib.IMAP4_SSL(source_imap_host)
  12. source_imap.login(source_imap_username,source_imap_password)
  13.  
  14. if not os.path.exists('Inbox'):
  15.     os.mkdir('Inbox')
  16. source_imap.select('Inbox')
  17.  
  18. status,data = source_imap.search(None,'ALL')
  19.  
  20. for message_number in data[0].split():
  21.     status,data = source_imap.fetch(message_number,'(RFC822)')
  22.     message = data[0][1]
  23.  
  24.     print('Inbox Message: {0}'.format(message_number.decode('utf-8')))
  25.  
  26.     file = open('Inbox/{0}.txt'.format(message_number.decode('utf-8')),'w')
  27.     file.write(message.decode('utf-8'))
  28.     file.close()
  29.  
  30. source_imap.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top