Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- HEURE_ENVOI="07:00"
- FICHIER_DONNEES="temp.txt"
- PASSWORD="ton_pwd"
- SENDER="ton_mail@gmail.com"
- RECEIVER="mail1@yahoo.fr,mail2@axiomeconcept.com,mail3@gmail.com"
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- import smtplib
- import time #Tempo
- def envoyerMail(mensaje):
- # create message object instance
- msg = MIMEMultipart()
- message = mensaje
- # setup the parameters of the message
- password = PASSWORD
- msg['From'] = SENDER
- msg['To'] = RECEIVER
- msg['Subject'] = "TEST ENVOI MAIL"
- # add in the message body
- msg.attach(MIMEText(message, 'plain'))
- print ("A")
- #create server
- server = smtplib.SMTP("smtp.gmail.com",587)
- print ("B create server smtplib.SMTP")
- server.starttls()
- # Login Credentials for sending the mail
- server.login(msg['From'], password)
- # send the message via the server.
- server.sendmail(msg['From'], msg['To'].split(","), msg.as_string())
- server.quit()
- print ("successfully sent email to %s:" % (msg['To']))
- def main():
- print ("Emailer")
- while True:
- if str( time.strftime("%H:%M"))==HEURE_ENVOI:
- print ("Envoi messages ",HEURE_ENVOI)
- message=""
- fichier= open(FICHIER_DONNEES, 'r')
- for ligne in fichier:
- message += ligne
- fichier.close()
- envoyerMail(message)
- time.sleep(61)
- time.sleep(10)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement