Guest User

Untitled

a guest
Jul 27th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # By Jonathan DePrizio, April 16, 2012
  4. # Licensed under "do whatever the hell you please with it" license.
  5.  
  6. ####################
  7. #  Configuration - this is required.
  8.  
  9. SMTPSERVER=""
  10. SMTPUSER=""
  11. SMTPPASS=""
  12. SMTPPORT=5125
  13.  
  14. # Your wireless provider.  Currently supported: verizonwireless.
  15. # It's easy to add more; just add them to the dictionary above
  16. # the import lines below.
  17.  
  18. WIRELESS_PROVIDER = "verizonwireless"
  19.  
  20. #  End of user-configurable options
  21. ####################
  22.  
  23. WIRELESS_LOOKUP = {'verizonwireless':'vtext.com'}
  24.  
  25. import subprocess, smtplib, sys
  26. from email.mime.text import MIMEText
  27. from email.mime.multipart import MIMEMultipart
  28. from optparse import OptionParser
  29. from socket import gethostname
  30.  
  31. options = OptionParser()
  32. options.add_option("-n", help="Your cell number.", default=False, dest="cellNumber")
  33. options.add_option("-c", help="The command you want to run.", dest="cmd", default=False)
  34. opts, args = options.parse_args()
  35.  
  36. if (not opts.cellNumber) or (not opts.cmd):
  37.         print "All arguments are required. "Use -h for help."
  38.        sys.exit(1)
  39.  
  40. if WIRELESS_PROVIDER not in WIRELESS_LOOKUP.keys():
  41.        print "Your wireless provider is not supported."
  42.        sys.exit(1)
  43.  
  44. DEST_EMAIL = str(opts.cellNumber) + "@" + WIRELESS_LOOKUP[WIRELESS_PROVIDER]
  45.  
  46. cmdExec = subprocess.Popen([opts.cmd], shell=True)
  47. rt = cmdExec.wait()
  48. msg = MIMEMultipart('alternative')
  49. msg['From'] = gethostname()
  50. msg['To'] = DEST_EMAIL
  51. msg.attach(MIMEText(msgBody, 'plain'))
  52.  
  53. try:
  54.        mailconn = smtplib.SMTP(SMTPSERVER, SMTPPORT)
  55.        mailconn.set_debuglevel(1)
  56.        mailconn.login(SMTPUSER, SMTPPASS)
  57.        mailconn.sendmail(SMTPUSER, DEST_EMAIL, msg.as_string())
  58.        mailconn.quit()
  59. except:
  60.        print "An error occurred sending the email.  Uh oh!"
  61.        sys.exit(1)
Add Comment
Please, Sign In to add comment