· 6 years ago · Aug 23, 2019, 10:52 PM
1import smtplib
2from email.mime.text import MIMEText
3from email.mime.multipart import MIMEMultipart
4from email.mime.base import MIMEBase
5from email import encoders
6import os.path
7import os, shutil
8import time
9
10count = 0
11email = '@gmail.com'
12password = 'INT'
13send_to_email = '@gmail.com'
14subject = 'Test sa slanjem i brisanjem 4' # The subject line
15message = 'sa attachmentom'
16file_location = 'C:\\Users\\myname\\Desktop\\pictures'
17folder = r'C:\Users\Borna\Desktop\pictures'
18
19msg = MIMEMultipart()
20msg['From'] = email
21msg['To'] = send_to_email
22while (count < 3):
23 count += 1
24 if os.path.exists(file_location) and os.path.getsize(file_location) > 0:
25 with ("pictures.log", "r") as log:
26 if not picture_file_name in log:
27 server = smtplib.SMTP('smtp.gmail.com', 587)
28 server.starttls()
29 server.login(email, password)
30 text = msg.as_string()
31 server.sendmail(email, send_to_email, text)
32 server.quit()
33 print('pictures sent')
34
35 for the_file in os.listdir(folder):
36 file_path = os.path.join(folder, the_file)
37 try:
38 if os.path.isfile(file_path):
39 os.unlink(file_path)
40 elif os.path.isdir(file_path):
41 shutil.rmtree(file_path)
42 except Exception as e:
43 print(e)
44 print('content of file deleted')
45 time.sleep(10)
46 print('scanning again')
47 else:
48 print('scanning again empty')
49 time.sleep(10)