Guest User

Untitled

a guest
Jan 23rd, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #!/usr/local/bin/python
  2. import imaplib
  3. import smtplib
  4. import sys
  5.  
  6. USERNAME = "" # no @cooper.edu
  7. PASSWORD = ""
  8. FORWARDTO = "" # full email address to forward to
  9.  
  10. if len(sys.argv) == 1:
  11. print """
  12. Cooper email forwarder tool by Jordan Perr.
  13. Requires Python 2.6 or 2.7
  14. \tperr@cooper.edu
  15.  
  16. USAGE: coopfwd.py standard|all
  17.  
  18. MODES:\tSTANDARD: Forwards only "unseen" messages and marks forwarded messages as "seen." This is standard "forwarding."
  19.  
  20. \tALL: Forwards ALL messages in your cooper.edu account. This takes a LONG TIME and will send you a LOT of emails. Be warned. Useful for a first time "import" into gmail.
  21.  
  22.  
  23. OUTPUT: The program outputs useful debugging information to standard out. Redirect it into a logfile by doing: coopfwd.py mode >> logfile.txt
  24.  
  25. """
  26. sys.exit()
  27.  
  28. print "starting"
  29. S = False
  30. M = imaplib.IMAP4_SSL("farley2.cooper.edu", 993)
  31. M.login(USERNAME, PASSWORD)
  32. M.select("INBOX")
  33. typ, data = M.search(None, 'ALL' if sys.argv[1] == "all" else "UNSEEN")
  34. print data
  35. if len(data[0].split()):
  36. S = smtplib.SMTP_SSL('farley2.cooper.edu', 465)
  37. #S.connect()
  38. S.login(USERNAME, PASSWORD)
  39. for num in data[0].split():
  40. print "forwarding email"
  41. typ, data = M.fetch(num, '(RFC822)')
  42. S.sendmail(USERNAME+"@cooper.edu", FORWARDTO, data[0][1])
  43. M.close()
  44. M.logout()
  45. if S:
  46. S.quit()
  47. print "done"
Add Comment
Please, Sign In to add comment