import smtplib, ssl, sys, requests, csv, time, zipfile, os, env sys.path.append("./env.py") from env import serveurMailPassword, serveurPort, serveurSmtp, serveurAdrresseMail, mailReception from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.application import MIMEApplication # FONCTION ZIP def zip_it(): zip = zipfile.ZipFile('./logs/stack-alert-logs.zip', mode='w') zip.write('./logs/python-alert.log') zip.close() # FONCTION IMPORT URL FROM CSV + TEST REQUEST def import_mails(): print(time.ctime()) mails = [] with open('./autres-destinataires.csv', newline='') as file: reader = csv.reader(file) for row in reader: # NETTOYAGE addr = str(row) mailraw = addr.strip('[]\'') mails.append(mailraw) return mails # FONCTION CLEAN OLD LOGS def clean_logs(): if os.path.exists('./logs/python-alert.log'): os.remove('/./logs/python-alert.log') if os.path.exists('/./logs/stack-alert-logs.zip'): os.remove('./logs/stack-alert-logs.zip') # FONCTION SEND MAIL def send_mail(mails): # EN-TETE EMAIL message = MIMEMultipart('mixed') message['From'] = serveurAdrresseMail message['To'] = mailReception message['CC'] = ",".join(mails) message['Subject'] = 'Rapport hebdo sites HS' # CONTENU (TEXT) contenu = '