Guest User

Untitled

a guest
Jun 4th, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #save img by gmail
  2. import smtplib
  3. from email.MIMEMultipart import MIMEMultipart
  4. from email.MIMEBase import MIMEBase
  5. from email.MIMEText import MIMEText
  6. from email import Encoders
  7. import os
  8. import time
  9. import sys
  10. import re
  11. import random
  12.  
  13. gmail_user = "toto@gmail.com"
  14. gmail_pwd = "titi"
  15.  
  16. def mail(to, subject, text, attach):
  17. msg = MIMEMultipart()
  18.  
  19. msg['From'] = gmail_user
  20. msg['To'] = to
  21. msg['Subject'] = subject
  22.  
  23. msg.attach(MIMEText(text))
  24.  
  25. part = MIMEBase('application', 'octet-stream')
  26. part.set_payload(open(attach, 'rb').read())
  27. Encoders.encode_base64(part)
  28. part.add_header('Content-Disposition',
  29. 'attachment; filename="%s"' % os.path.basename(attach))
  30. msg.attach(part)
  31.  
  32. mailServer = smtplib.SMTP("smtp.gmail.com", 587)
  33. mailServer.ehlo()
  34. mailServer.starttls()
  35. mailServer.ehlo()
  36. mailServer.login(gmail_user, gmail_pwd)
  37. mailServer.sendmail(gmail_user, to, msg.as_string())
  38. # Should be mailServer.quit(), but that crashes...
  39. mailServer.close()
  40. def send(location=""):
  41. if location != "" :
  42. location = location.replace("\\","/")
  43. fichpython = re.compile(r"\.py")
  44. fichjpg = re.compile(r"\.jpg|\.jpeg|\.JPG")
  45. fichpng = re.compile(r"\.png|\.PNG|\.Png")
  46. fichavi = re.compile(r"\.avi|\.mpg|\.AVI")
  47. i = 0
  48. for file in os.listdir(""):
  49. time.sleep(random.uniform(1,3))
  50. if not fichpython.search(file):
  51. i= i +1
  52. if i > 0 :
  53. print file
  54. if fichjpg.search(file):
  55. mail("toto@gmail.com",file,file,file)
  56. else :
  57. if fichpng.search(file):
  58. mail("toto@gmail.com",file,file,file)
  59. else :
  60. if fichavi.search(file):
  61. mail("toto@gmail.com",file,file,file)
  62.  
  63.  
  64. if __name__ == "__main__":
  65. try :
  66. nfile = sys.argv[1]
  67. except :
  68. nfile = ""
  69. send(location=nfile)
Add Comment
Please, Sign In to add comment