1849 characters | 50 lines | 1.81 KB
DOWNLOAD | RAW | EMBED | CREATE NEW VERSION OF THIS PASTE | REPORT ABUSE | x
  1.     #Author: Spiros Gezerlis - gezerlis_gmail_com
  2.     import smtplib
  3.     from email.mime.image import MIMEImage
  4.     from email.mime.multipart import MIMEMultipart
  5.     from time import strftime
  6.     import commands
  7.     import time
  8.      
  9.     #Setting variables
  10.     INTERVAL = 60
  11.     WEBCAM_IMAGE = "/path/to/file.png"
  12.     WEBCAM_RESOLUTION = "640x480" #1280x1024 1024x768 640x480
  13.     WEBCAM_CMD = "fswebcam -r "+WEBCAM_RESOLUTION+" "+WEBCAM_IMAGE
  14.     EMAIL_SUBJECT = 'Screenshot @ '+strftime("%Y-%m-%d %H:%M:%S") +" ("+WEBCAM_RESOLUTION+")"
  15.     EMAIL_SENDER = "[email protected]"
  16.     EMAIL_RECIPIENT_LIST = ["[email protected]"]
  17.     LINE = "=============="
  18.     COMMASPACE = ', '
  19.      
  20.     while (1):
  21.         #Taking screenshot
  22.         print LINE
  23.         print "Starting "+EMAIL_SUBJECT+" to be sent via email"
  24.         commands.getstatusoutput(WEBCAM_CMD)
  25.         print "Webcam: "+WEBCAM_CMD
  26.      
  27.         #Constucting email
  28.         print "Constructing email"
  29.         msg = MIMEMultipart()
  30.         msg['Subject'] = EMAIL_SUBJECT
  31.         msg['From'] = EMAIL_SENDER
  32.         msg['To'] = COMMASPACE.join(EMAIL_RECIPIENT_LIST)
  33.      
  34.         #Opening and Attaching 'image' file to email
  35.         print "Attaching "+WEBCAM_IMAGE+" to email"
  36.         fp = open(WEBCAM_IMAGE, 'rb')
  37.         img = MIMEImage(fp.read())
  38.         fp.close()
  39.         msg.attach(img)
  40.      
  41.         # Send the email via linux's own SMTP server and sleep for 'interval' seconds
  42.         print "Sending email @ ",strftime("%Y-%m-%d %H:%M:%S")
  43.         s = smtplib.SMTP('localhost')
  44.         s.sendmail(EMAIL_SENDER, EMAIL_RECIPIENT_LIST, msg.as_string())
  45.         s.quit()
  46.         print "Email sent @ ",strftime("%Y-%m-%d %H:%M:%S")
  47.         print "Sleeping for "+str(INTERVAL)+" secs"
  48.         print LINE
  49.         print
  50.         time.sleep(INTERVAL)