Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #save img by gmail
- import smtplib
- from email.MIMEMultipart import MIMEMultipart
- from email.MIMEBase import MIMEBase
- from email.MIMEText import MIMEText
- from email import Encoders
- import os
- import time
- import sys
- import re
- import random
- gmail_user = "toto@gmail.com"
- gmail_pwd = "titi"
- def mail(to, subject, text, attach):
- msg = MIMEMultipart()
- msg['From'] = gmail_user
- msg['To'] = to
- msg['Subject'] = subject
- msg.attach(MIMEText(text))
- part = MIMEBase('application', 'octet-stream')
- part.set_payload(open(attach, 'rb').read())
- Encoders.encode_base64(part)
- part.add_header('Content-Disposition',
- 'attachment; filename="%s"' % os.path.basename(attach))
- msg.attach(part)
- mailServer = smtplib.SMTP("smtp.gmail.com", 587)
- mailServer.ehlo()
- mailServer.starttls()
- mailServer.ehlo()
- mailServer.login(gmail_user, gmail_pwd)
- mailServer.sendmail(gmail_user, to, msg.as_string())
- # Should be mailServer.quit(), but that crashes...
- mailServer.close()
- def send(location=""):
- if location != "" :
- location = location.replace("\\","/")
- fichpython = re.compile(r"\.py")
- fichjpg = re.compile(r"\.jpg|\.jpeg|\.JPG")
- fichpng = re.compile(r"\.png|\.PNG|\.Png")
- fichavi = re.compile(r"\.avi|\.mpg|\.AVI")
- i = 0
- for file in os.listdir(""):
- time.sleep(random.uniform(1,3))
- if not fichpython.search(file):
- i= i +1
- if i > 0 :
- print file
- if fichjpg.search(file):
- mail("toto@gmail.com",file,file,file)
- else :
- if fichpng.search(file):
- mail("toto@gmail.com",file,file,file)
- else :
- if fichavi.search(file):
- mail("toto@gmail.com",file,file,file)
- if __name__ == "__main__":
- try :
- nfile = sys.argv[1]
- except :
- nfile = ""
- send(location=nfile)
Add Comment
Please, Sign In to add comment