Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python
- import imaplib
- import smtplib
- import sys
- USERNAME = "" # no @cooper.edu
- PASSWORD = ""
- FORWARDTO = "" # full email address to forward to
- if len(sys.argv) == 1:
- print """
- Cooper email forwarder tool by Jordan Perr.
- Requires Python 2.6 or 2.7
- \tperr@cooper.edu
- USAGE: coopfwd.py standard|all
- MODES:\tSTANDARD: Forwards only "unseen" messages and marks forwarded messages as "seen." This is standard "forwarding."
- \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.
- OUTPUT: The program outputs useful debugging information to standard out. Redirect it into a logfile by doing: coopfwd.py mode >> logfile.txt
- """
- sys.exit()
- print "starting"
- S = False
- M = imaplib.IMAP4_SSL("farley2.cooper.edu", 993)
- M.login(USERNAME, PASSWORD)
- M.select("INBOX")
- typ, data = M.search(None, 'ALL' if sys.argv[1] == "all" else "UNSEEN")
- print data
- if len(data[0].split()):
- S = smtplib.SMTP_SSL('farley2.cooper.edu', 465)
- #S.connect()
- S.login(USERNAME, PASSWORD)
- for num in data[0].split():
- print "forwarding email"
- typ, data = M.fetch(num, '(RFC822)')
- S.sendmail(USERNAME+"@cooper.edu", FORWARDTO, data[0][1])
- M.close()
- M.logout()
- if S:
- S.quit()
- print "done"
Add Comment
Please, Sign In to add comment