From 5fc7af37a101015ec6ef0aee991743a1d7832243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ch=C3=A9rifBALDE?= Date: Tue, 5 Apr 2022 15:44:38 +0200 Subject: [PATCH] 05/04/22 - 15h40 --- email_mgt.py | 246 ++++++++++++++++++++++++++++----------------------- wrapper.py | 9 +- 2 files changed, 139 insertions(+), 116 deletions(-) diff --git a/email_mgt.py b/email_mgt.py index 2f40959..8cb1436 100644 --- a/email_mgt.py +++ b/email_mgt.py @@ -5,6 +5,9 @@ from email.mime.base import MIMEBase from email import encoders import locale import datetime +import inspect +import sys, os +import prj_common as mycommon locale.setlocale(category=locale.LC_ALL, locale='fr_FR.utf8') smtp_address = 'smtp.ionos.fr' @@ -27,150 +30,167 @@ password = 'cYa1pk56Zx7EzKmg' def send_user_account_mail(message, account_mail): - tomorrow = datetime.date.today() + datetime.timedelta(days=1) - tomorrow_day = tomorrow.strftime("%A") + try: + tomorrow = datetime.date.today() + datetime.timedelta(days=1) + tomorrow_day = tomorrow.strftime("%A") - print("debut envoi mail de test ") - # on rentre les renseignements pris sur le site du fournisseur + print("debut envoi mail de test ") + # on rentre les renseignements pris sur le site du fournisseur - msg = MIMEMultipart("alternative") + msg = MIMEMultipart("alternative") - msg['Subject'] = 'MySy Training : Activez votre compte ' - msg['From'] = 'billardman01@hotmail.com' - msg['To'] = str(account_mail) + msg['Subject'] = 'MySy Training : Activez votre compte ' + msg['From'] = 'billardman01@hotmail.com' + msg['To'] = str(account_mail) - html = ''' - - - - -
-

- Mysy Training Logo

-
-
-
-
- Bonjour -
- -Votre adresse e-mail a bien été enregistrée sur le site MySy-Training.
-Pour valider votre compte, veuillez cliquer sur le lien ci-dessous : -
-
- - -
- - - CLIQUEZ ICI ==> LOCALHOST - - - -

Cordialement
- L'equipe informatique de MySy -

-

-
- -
- - - - '''.format(code=tomorrow_day, objId=message) + html = ''' + + + + +
+

+ Mysy Training Logo

+
+
+
+
+ Bonjour +
+ + Votre adresse e-mail a bien été enregistrée sur le site MySy-Training.
+ Pour valider votre compte, veuillez cliquer sur le lien ci-dessous : +
+
+ + +
+ + + CLIQUEZ ICI ==> LOCALHOST + + + +

Cordialement
+ L'equipe informatique de MySy +

+

+
+ +
+ + + + '''.format(code=tomorrow_day, objId=message) - html_mime = MIMEText(html, 'html') + html_mime = MIMEText(html, 'html') - # msg.attach(texte_mime) - msg.attach(html_mime) + # msg.attach(texte_mime) + msg.attach(html_mime) - print("html_mime ="+str(html)) + print("html_mime ="+str(html)) - toaddr = str(account_mail) - cc = ['billardman01@hotmail.com'] - toaddrs = [toaddr] + cc + toaddr = str(account_mail) + cc = ['billardman01@hotmail.com'] + toaddrs = [toaddr] + cc - # msg.attach(MIMEText(open(filename).read())) + # msg.attach(MIMEText(open(filename).read())) - with smtplib.SMTP(smtp_address, port) as server: - server.starttls() # Secure the connection + with smtplib.SMTP(smtp_address, port) as server: + server.starttls() # Secure the connection - server.login(user, password) - server.sendmail(sender, toaddrs, msg.as_string()) - print("mail successfully sent to "+str(toaddrs)) + server.login(user, password) + server.sendmail(sender, toaddrs, msg.as_string()) + 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): - 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)] - toaddrs = ", ".join(receiver) + try: + 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 ") - # on rentre les renseignements pris sur le site du fournisseur + print("debut envoi mail de test ") + # on rentre les renseignements pris sur le site du fournisseur - msg = MIMEMultipart("alternative") + msg = MIMEMultipart("alternative") - msg['Subject'] = 'MySy : test email activation compte ' - msg['From'] = 'billardman01@hotmail.com' - msg['To'] = str(toaddrs) - msg['Cc'] = 'cbalde@mysy-training.com' + msg['Subject'] = 'MySy : test email activation compte ' + msg['From'] = 'billardman01@hotmail.com' + msg['To'] = str(toaddrs) + msg['Cc'] = 'cbalde@mysy-training.com' - html = ''' - - -

Bonjour

-

Vous venez de créer un compte partenaire. - Pour activier votre compte, merci de cliquer ici

- - - https://apimysy.iexercice.com/myclass/api/valide_partnair_account/{objId} - - - - - ou - - - http://127.0.0.1:5000/myclass/api/valide_partnair_account/{objId} - - -

Cordialement
- L'equipe informatique de MySy -

- - - - '''.format(code=tomorrow_day, objId=message) + html = ''' + + +

Bonjour

+

Vous venez de créer un compte partenaire. + Pour activier votre compte, merci de cliquer ici

+ + + https://apimysy.iexercice.com/myclass/api/valide_partnair_account/{objId} + + + + + ou + + + http://127.0.0.1:5000/myclass/api/valide_partnair_account/{objId} + + +

Cordialement
+ L'equipe informatique de MySy +

+ + + + '''.format(code=tomorrow_day, objId=message) - html_mime = MIMEText(html, 'html') + html_mime = MIMEText(html, 'html') - # msg.attach(texte_mime) - msg.attach(html_mime) + # msg.attach(texte_mime) + msg.attach(html_mime) - print("html_mime ="+str(html)) + print("html_mime ="+str(html)) - with smtplib.SMTP(smtp_address, port) as server: - server.starttls() # Secure the connection + with smtplib.SMTP(smtp_address, port) as server: + 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") diff --git a/wrapper.py b/wrapper.py index 61e3f26..e1c73dc 100644 --- a/wrapper.py +++ b/wrapper.py @@ -68,7 +68,8 @@ def get_recherche_gle_class(sentence): return insertObject 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 @@ -94,7 +95,8 @@ def get_class_by_list_attr(attribut, list_values): return insertObject 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 @@ -119,7 +121,8 @@ def update_class_by_attribut(objId, attribut, value): 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