commit
14f66dcc90
@ -0,0 +1,4 @@ |
||||
serveurSmtp = "mail.smtp.net" |
||||
serveurPort = 465 |
||||
serveurAdrresseMail= "secretsanta@domaine.com" |
||||
serveurMailPassword = "mot-de-passe" |
|
@ -0,0 +1,73 @@ |
||||
import random, smtplib, ssl, sys, csv |
||||
sys.path.append("env.py") |
||||
from env import serveurMailPassword, serveurPort, serveurSmtp, serveurAdrresseMail |
||||
|
||||
## CLASSE ## |
||||
class Personne: |
||||
def __init__(self, name, email): |
||||
self.name = name |
||||
self.email = email |
||||
|
||||
def getName(self): |
||||
return self.name |
||||
|
||||
def getEmail(self): |
||||
return self.email |
||||
|
||||
## FONCTIONS ## |
||||
def import_from_csv(): |
||||
personnes = [] |
||||
with open('participants.csv', 'r') as file: |
||||
reader = csv.reader(file) |
||||
for row in reader: |
||||
personne = Personne(row[0], row[1]) |
||||
personnes.append(personne) |
||||
return personnes |
||||
|
||||
def split_names(names): |
||||
return [name.strip() for name in names.split(",")] |
||||
|
||||
def make_pairs(names): |
||||
return [ |
||||
(name, names[(i + 1) % len(names)]) |
||||
for i, name in enumerate(names) |
||||
] |
||||
|
||||
def send_mail(mail, emailAddress): |
||||
port = serveurPort |
||||
smtp_server = serveurSmtp |
||||
sender_email = serveurAdrresseMail |
||||
receiver_email = emailAddress |
||||
password = serveurMailPassword |
||||
message = """\ |
||||
Sujet: Secret Santa |
||||
|
||||
{mail}\ |
||||
Joyeux Noel!""" |
||||
|
||||
context = ssl.create_default_context() |
||||
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: |
||||
try: |
||||
server.login(sender_email, password) |
||||
server.sendmail(sender_email, receiver_email, message.format(mail=mail)) |
||||
except Exception as e: |
||||
print("Houston... on a un problème! erreur: " + str(e)) |
||||
finally: |
||||
server.quit() |
||||
|
||||
# ## MAIN ## |
||||
personnes = import_from_csv() |
||||
|
||||
# mélange aléatoire des noms |
||||
random.shuffle(personnes) |
||||
pairs = make_pairs(personnes) |
||||
|
||||
# répartition et envoie des mails |
||||
for donneur, receveur in pairs: |
||||
# Pour test le print |
||||
#print("{} va offrir un cadeau à {}".format(donneur.name, receveur.name)) |
||||
mail = 'Bonjour {}, cette annee, tu vas offrir un cadeau a {}'.format(donneur.name, receveur.name) |
||||
|
||||
send_mail(mail, donneur.email) |
||||
|
||||
print("Secret santa est passé...") |
@ -0,0 +1,60 @@ |
||||
import random, smtplib, ssl, sys, csv |
||||
sys.path.append("env.py") |
||||
from env import serveurMailPassword, serveurPort, serveurSmtp, serveurAdrresseMail |
||||
|
||||
|
||||
## CLASSE ## |
||||
class Personne: |
||||
def __init__(self, name, email): |
||||
self.name = name |
||||
self.email = email |
||||
|
||||
def getName(self): |
||||
return self.name |
||||
|
||||
def getEmail(self): |
||||
return self.email |
||||
|
||||
## FONCTIONS ## |
||||
def import_from_csv(): |
||||
personnes = [] |
||||
with open('participants.csv', 'r') as file: |
||||
reader = csv.reader(file) |
||||
for row in reader: |
||||
personne = Personne(row[0], row[1]) |
||||
personnes.append(personne) |
||||
return personnes |
||||
|
||||
def send_mail(mail, emailAddress): |
||||
port = serveurPort |
||||
smtp_server = serveurSmtp |
||||
sender_email = serveurAdrresseMail |
||||
receiver_email = emailAddress |
||||
password = serveurMailPassword |
||||
message = """\ |
||||
Sujet: Secret Santa |
||||
|
||||
{mail} |
||||
|
||||
Joyeuses fetes!""" |
||||
|
||||
context = ssl.create_default_context() |
||||
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: |
||||
try: |
||||
server.login(sender_email, password) |
||||
server.sendmail(sender_email, receiver_email, message.format(mail=mail)) |
||||
except Exception as e: |
||||
print("Houston... on a un problème! erreur: " + str(e)) |
||||
finally: |
||||
server.quit() |
||||
|
||||
# ## MAIN ## |
||||
personnes = import_from_csv() |
||||
|
||||
# répartition et envoie des mails |
||||
for donneur in personnes: |
||||
mail = 'Bonjour {}, juste un petit mail a retirer des courriers indesirables\n pour recevoir le mail du secret santa le soir venu.'.format(donneur.name) |
||||
|
||||
send_mail(mail, donneur.email) |
||||
|
||||
print("Anti-spam envoyé...") |
Loading…
Reference in new issue