05/04/22 - 15h40

master
ChérifBALDE 2022-04-05 15:44:38 +02:00 committed by cherif
parent 2cb62b2e91
commit 5fc7af37a1
2 changed files with 139 additions and 116 deletions

View File

@ -5,6 +5,9 @@ from email.mime.base import MIMEBase
from email import encoders from email import encoders
import locale import locale
import datetime import datetime
import inspect
import sys, os
import prj_common as mycommon
locale.setlocale(category=locale.LC_ALL, locale='fr_FR.utf8') locale.setlocale(category=locale.LC_ALL, locale='fr_FR.utf8')
smtp_address = 'smtp.ionos.fr' smtp_address = 'smtp.ionos.fr'
@ -27,150 +30,167 @@ password = 'cYa1pk56Zx7EzKmg'
def send_user_account_mail(message, account_mail): def send_user_account_mail(message, account_mail):
tomorrow = datetime.date.today() + datetime.timedelta(days=1) try:
tomorrow_day = tomorrow.strftime("%A") tomorrow = datetime.date.today() + datetime.timedelta(days=1)
tomorrow_day = tomorrow.strftime("%A")
print("debut envoi mail de test ") print("debut envoi mail de test ")
# on rentre les renseignements pris sur le site du fournisseur # on rentre les renseignements pris sur le site du fournisseur
msg = MIMEMultipart("alternative") msg = MIMEMultipart("alternative")
msg['Subject'] = 'MySy Training : Activez votre compte ' msg['Subject'] = 'MySy Training : Activez votre compte '
msg['From'] = 'billardman01@hotmail.com' msg['From'] = 'billardman01@hotmail.com'
msg['To'] = str(account_mail) msg['To'] = str(account_mail)
html = ''' html = '''
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<div style="background-color:#eee;padding:0px;text-align:center;width:100%"> <div style="background-color:#eee;padding:0px;text-align:center;width:100%">
<h2 style="font-family:Georgia, 'Times New Roman', Times, serif;color#454349;"> <h2 style="font-family:Georgia, 'Times New Roman', Times, serif;color#454349;">
<img src="http://88.170.110.220/img/MYSY-LOGO-BLUE.png" alt="Mysy Training Logo" width="110px" height="70px"/> </h2> <img src="http://88.170.110.220/img/MYSY-LOGO-BLUE.png" alt="Mysy Training Logo" width="110px" height="70px"/> </h2>
</div> </div>
<div style="padding:20px 0px;text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;color#454349;font-size:2rem;"> <div style="padding:20px 0px;text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;color#454349;font-size:2rem;">
<div style="width:100%"> <div style="width:100%">
<div style="text-align:center;"> <div style="text-align:center;">
Bonjour Bonjour
<div style="padding:20px 0px;text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;color#454349;font-size:1.2rem;"> <div style="padding:20px 0px;text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;color#454349;font-size:1.2rem;">
Votre adresse e-mail a bien été enregistrée sur le site <font color="green">MySy-Training</font>. <br> Votre adresse e-mail a bien été enregistrée sur le site <font color="green">MySy-Training</font>. <br>
Pour valider votre compte, veuillez cliquer sur le lien <font color="green">ci-dessous :</font> Pour valider votre compte, veuillez cliquer sur le lien <font color="green">ci-dessous :</font>
<br/> <br/>
<br/> <br/>
<div style="background-color:#1962AB;width:20%;text-align:center;margin-left:auto; margin-right:auto;"> <div style="background-color:#1962AB;width:20%;text-align:center;margin-left:auto; margin-right:auto;">
<b> <a href="https://apimysy.iexercice.com/myclass/api/valide_user_account/{objId}" target="_blank" style="color: white;"> <b> <a href="https://apimysy.iexercice.com/myclass/api/valide_user_account/{objId}" target="_blank" style="color: white;">
CLIQUEZ ICI CLIQUEZ ICI
</a> </a>
</b> </b>
</div> </div>
</font> </font>
<br/> <br/>
<b> <b>
<a href="http://127.0.0.1:5000/myclass/api/valide_user_account/{objId}" target="_blank" style="font-size:0.5rem;" > <a href="http://127.0.0.1:5000/myclass/api/valide_user_account/{objId}" target="_blank" style="font-size:0.5rem;" >
CLIQUEZ ICI ==> LOCALHOST CLIQUEZ ICI ==> LOCALHOST
</b> </b>
</a> </a>
<p>Cordialement<br> <p>Cordialement<br>
L'equipe informatique de MySy L'equipe informatique de MySy
</p> </p>
</p> </p>
</div> </div>
</div> </div>
</body> </body>
</html> </html>
'''.format(code=tomorrow_day, objId=message) '''.format(code=tomorrow_day, objId=message)
html_mime = MIMEText(html, 'html') html_mime = MIMEText(html, 'html')
# msg.attach(texte_mime) # msg.attach(texte_mime)
msg.attach(html_mime) msg.attach(html_mime)
print("html_mime ="+str(html)) print("html_mime ="+str(html))
toaddr = str(account_mail) toaddr = str(account_mail)
cc = ['billardman01@hotmail.com'] cc = ['billardman01@hotmail.com']
toaddrs = [toaddr] + cc toaddrs = [toaddr] + cc
# msg.attach(MIMEText(open(filename).read())) # msg.attach(MIMEText(open(filename).read()))
with smtplib.SMTP(smtp_address, port) as server: with smtplib.SMTP(smtp_address, port) as server:
server.starttls() # Secure the connection server.starttls() # Secure the connection
server.login(user, password) server.login(user, password)
server.sendmail(sender, toaddrs, msg.as_string()) server.sendmail(sender, toaddrs, msg.as_string())
print("mail successfully sent to "+str(toaddrs)) mycommon.myprint("mail successfully sent to "+str(toaddrs))
return True
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'envoyer l'email de notification "
def send_partner_account_mail(message, account_mail): def send_partner_account_mail(message, account_mail):
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
tomorrow_day = tomorrow.strftime("%A")
receiver = ["cherif.balde@yahoo.fr","cbalde@bigben-connected.com",str(account_mail)] try:
toaddrs = ", ".join(receiver) tomorrow = datetime.date.today() + datetime.timedelta(days=1)
tomorrow_day = tomorrow.strftime("%A")
print(" mail enoye à : "+toaddrs) receiver = ["cherif.balde@yahoo.fr","cbalde@bigben-connected.com",str(account_mail)]
toaddrs = ", ".join(receiver)
print(" mail enoye à : "+toaddrs)
print("debut envoi mail de test ") print("debut envoi mail de test ")
# on rentre les renseignements pris sur le site du fournisseur # on rentre les renseignements pris sur le site du fournisseur
msg = MIMEMultipart("alternative") msg = MIMEMultipart("alternative")
msg['Subject'] = 'MySy : test email activation compte ' msg['Subject'] = 'MySy : test email activation compte '
msg['From'] = 'billardman01@hotmail.com' msg['From'] = 'billardman01@hotmail.com'
msg['To'] = str(toaddrs) msg['To'] = str(toaddrs)
msg['Cc'] = 'cbalde@mysy-training.com' msg['Cc'] = 'cbalde@mysy-training.com'
html = ''' html = '''
<html> <html>
<body> <body>
<p>Bonjour</p> <p>Bonjour</p>
<p>Vous venez de créer un compte partenaire. <p>Vous venez de créer un compte partenaire.
Pour activier votre compte, merci de cliquer ici </b> </p> Pour activier votre compte, merci de cliquer ici </b> </p>
<b> <b>
<a href="https://apimysy.iexercice.com/myclass/api/valide_partnair_account/{objId}" target="_blank" > <a href="https://apimysy.iexercice.com/myclass/api/valide_partnair_account/{objId}" target="_blank" >
https://apimysy.iexercice.com/myclass/api/valide_partnair_account/{objId} https://apimysy.iexercice.com/myclass/api/valide_partnair_account/{objId}
</b> </b>
</a> </a>
<a> <a>
ou ou
<b> <b>
<a href="http://127.0.0.1:5000/myclass/api/valide_partnair_account/{objId}" target="_blank" > <a href="http://127.0.0.1:5000/myclass/api/valide_partnair_account/{objId}" target="_blank" >
http://127.0.0.1:5000/myclass/api/valide_partnair_account/{objId} http://127.0.0.1:5000/myclass/api/valide_partnair_account/{objId}
</b> </b>
</a> </a>
<p>Cordialement<br> <p>Cordialement<br>
L'equipe informatique de MySy L'equipe informatique de MySy
</p> </p>
</body> </body>
</html> </html>
'''.format(code=tomorrow_day, objId=message) '''.format(code=tomorrow_day, objId=message)
html_mime = MIMEText(html, 'html') html_mime = MIMEText(html, 'html')
# msg.attach(texte_mime) # msg.attach(texte_mime)
msg.attach(html_mime) msg.attach(html_mime)
print("html_mime ="+str(html)) print("html_mime ="+str(html))
with smtplib.SMTP(smtp_address, port) as server: with smtplib.SMTP(smtp_address, port) as server:
server.starttls() # Secure the connection server.starttls() # Secure the connection
server.login(user, password)
server.sendmail(sender, toaddrs, msg.as_string())
print("mail successfully sent")
return True
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'envoyer l'email de notification"
server.login(user, password)
server.sendmail(sender, toaddrs, msg.as_string())
print("mail successfully sent")

View File

@ -68,7 +68,8 @@ def get_recherche_gle_class(sentence):
return insertObject return insertObject
except Exception as e: except Exception as e:
mycommon.myprint(e) exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False return False
@ -94,7 +95,8 @@ def get_class_by_list_attr(attribut, list_values):
return insertObject return insertObject
except Exception as e: except Exception as e:
mycommon.myprint(e) exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False return False
@ -119,7 +121,8 @@ def update_class_by_attribut(objId, attribut, value):
except Exception as e: except Exception as e:
mycommon.myprint(e) exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False return False