Elyos_FI_Back_Office/email_mgt.py

597 lines
20 KiB
Python

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import locale
import datetime
import inspect
import sys, os
import prj_common as mycommon
import GlobalVariable as MYSY_GV
locale.setlocale(category=locale.LC_ALL, locale='fr_FR.utf8')
smtp_address = 'smtp-relay.sendinblue.com'
port = 587
sender = 'contact@mysy-training.com'
receiver = ["cbalde3@mysy-training.com","billardman1@gmail.com"]
user = 'contact@mysy-training.com'
password = 'yGmzqBfrjb3YCvQN'
def send_user_account_mail(message, account_mail):
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
msg = MIMEMultipart("alternative")
msg['Subject'] = 'MySy Training : Activez votre compte '
msg['From'] = 'contact@mysy-training.com'
msg['To'] = str(account_mail)
html = '''
<!DOCTYPE html>
<html>
<body>
<div style="background-color:#eee;padding:0px;text-align:center;width:100%">
<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>
</div>
<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="text-align:center;">
Bonjour
<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>
Pour valider votre compte, veuillez cliquer sur le lien ci-dessous :
<br/>
<br/>
<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;">
CLIQUEZ ICI
</a>
</b>
</div>
</font>
<br/>
<b>
<p>Cordialement<br>
MySy Training Technology<br>
Contact : +337 69 20 39 45<br>
Email : contact@mysy-training.com<br>
</p>
</p>
</div>
</div>
</body>
</html>
'''.format(code=tomorrow_day, objId=message)
html_mime = MIMEText(html, 'html')
# msg.attach(texte_mime)
msg.attach(html_mime)
print("html_mime ="+str(html))
toaddr = str(account_mail)
cc = ['contact@mysy-training.com']
toaddrs = [toaddr] + cc
# msg.attach(MIMEText(open(filename).read()))
with smtplib.SMTP(smtp_address, port) as server:
server.starttls() # Secure the connection
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'envoyer l'email de notification "
'''
Cette fonction envoie un mail de remerciement apres l'activation
du compte d'un utilisateur
'''
def send_user_thks_mail(message, account_mail):
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
msg = MIMEMultipart("alternative")
msg['Subject'] = 'MySy Training : Votre compte est actif '
msg['From'] = 'contact@mysy-training.com'
msg['To'] = str(account_mail)
html = '''
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://88.170.110.220/mysy_css/mysy_css.css">
</head>
<body>
<div style="background-color:#eee;padding:0px;text-align:center;width:100%">
<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>
</div>
<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="text-align:center;" class="p">
Bonjour
<div style="padding:20px 0px;text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;color#454349;font-size:1.2rem;">
Vous venez d'activer votre compte sur le moteur de recherche <font color="green">MySy-Training</font>. <br>
Merci à vous.
<br/>
<br/>
<br/>
<br/>
<b> Suivez l'actualité des formations depuis nos medias : <br/>
<a href="https://apimysy.iexercice.com/myclass/api/valide_user_account/{objId}" target="_blank" >
Facebook
</a> &nbsp;
<a href="https://apimysy.iexercice.com/myclass/api/valide_user_account/{objId}" target="_blank" >
LinkedIn
</a>&nbsp;
<a href="https://apimysy.iexercice.com/myclass/api/valide_user_account/{objId}" target="_blank" >
Twitter
</a>&nbsp;
</b>
</div>
</font>
<br/>
</div>
</div>
<div class='Box_div'>
<div class='Container_div'>
<div class='Row_Div'>
<div class='Column_div'>
<div class='Heading_p'>MySy Training Technology</div>
<a href="/QuiSommesNous/#desc" class='FooterLink_a'>À propos de nous</a>
<a href="/QuiSommesNous/#vision" class='FooterLink_a'>Notre vision</a>
<a href="/ContactezNous" class='FooterLink_a'>Nous contacter</a>
</div>
<div class='Column_div'>
<div class='Heading_p'>Contact Us</div>
<a href="#" class='FooterLink_a'>Paris</a>
<a href="#" class='FooterLink_a'>Geneve</a>
<a href="#" class='FooterLink_a'>Bruxelles</a>
</div>
<div class='Column_div'>
<div class='Heading_p'>Social Media</div>
<a href="https://www.facebook.com/profile.php?id=100080411044908" class='FooterLink_a'>
<i class="fab fa-facebook-f">
<span style={{ marginLeft: "10px" }}>
Facebook
</span>
</i>
</a>
<a href="https://www.linkedin.com/in/mysy-training-96b53a237/" class='FooterLink_a'>
<i class="fab fa-instagram">
<span style={{ marginLeft: "10px" }}>
LinkedIn
</span>
</i>
</a>
<a href="https://twitter.com/mysy_training" class='FooterLink_a'>
<i class="fab fa-twitter">
<span style={{ marginLeft: "10px" }}>
Twitter
</span>
</i>
</a>
<a href="https://www.youtube.com/" class='FooterLink_a'>
<i class="fab fa-youtube">
<span style={{ marginLeft: "10px" }}>
Youtube
</span>
</i>
</a>
</div>
</div>
</div>
<br />
<hr />
<div style="font-size:0.5rem;">
© 2022 Mysy Training Technology. Tous droits réservés. MySy Training Technology est une marque déposée.
Mentions légales.
</div>
</div>
</body>
</html>
'''.format(code=tomorrow_day, objId=message)
html_mime = MIMEText(html, 'html')
# msg.attach(texte_mime)
msg.attach(html_mime)
print("html_mime =" + str(html))
toaddr = str(account_mail)
cc = ['contact@mysy-training.com']
toaddrs = [toaddr] + cc
# msg.attach(MIMEText(open(filename).read()))
with smtplib.SMTP(smtp_address, port) as server:
server.starttls() # Secure the connection
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'envoyer l'email de notification "
def send_partner_account_mail(message, account_mail):
try:
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)
print(" mail enoye à : "+toaddrs)
print("debut envoi mail de test ")
# on rentre les renseignements pris sur le site du fournisseur
msg = MIMEMultipart("alternative")
msg['Subject'] = 'MySy : test email activation compte '
msg['From'] = 'contact@mysy-training.com'
msg['To'] = str(toaddrs)
msg['Cc'] = 'cbalde@mysy-training.com'
html = '''
<html>
<body>
<p>Bonjour</p>
<p>Vous venez de créer un compte partenaire.
Pour activier votre compte, merci de cliquer ici </b> </p>
<b>
<a href="https://apimysy.iexercice.com/myclass/api/valide_partnair_account/{objId}" target="_blank" >
https://apimysy.iexercice.com/myclass/api/valide_partnair_account/{objId}
</b>
</a>
<a>
ou
<b>
<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}
</b>
</a>
<p>Cordialement<br>
L'equipe informatique de MySy
</p>
</body>
</html>
'''.format(code=tomorrow_day, objId=message)
html_mime = MIMEText(html, 'html')
# msg.attach(texte_mime)
msg.attach(html_mime)
print("html_mime ="+str(html))
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'envoyer l'email de notification"
'''
Envoie de l'email de reinitialisation du mot de passe du user
'''
def send_user_init_pwd_mail(token, account_mail):
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
msg = MIMEMultipart("alternative")
msg['Subject'] = '[MySy Training Technology] : Reinitialisez votre mot de passe'
msg['From'] = 'contact@mysy-training.com'
msg['To'] = str(account_mail)
html = '''
<!DOCTYPE html>
<html>
<body>
<div style="background-color:#eee;padding:0px;text-align:center;width:100%">
<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>
</div>
<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="text-align:center;">
Bonjour
<div style="padding:20px 0px;text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;color#454349;font-size:1.2rem;">
Nous avons reçu une demande de réinitialisation du mot de passe de votre compte <font color="green">MySy-Training</font>.<br/>
Veuillez cliquer sur le bouton ci-dessous pour le réinitialiser.
. <br/>
<br/>
<div style="background-color:#1962AB;width:20%;text-align:center;margin-left:auto; margin-right:auto;">
<b> <a href="https://www.mysy-training.com/ResetUserPwd/{objId}" target="_blank" style="color: white;">
Changez de mot de passe
</a>
</b>
</div>
</font>
<br/>
<p>Cordialement<br>
MySy Training Technology<br>
Contact : +337 69 20 39 45<br>
Email : contact@mysy-training.com<br>
</p>
</p>
</div>
</div>
</body>
</html>
'''.format(code=tomorrow_day, objId=token)
html_mime = MIMEText(html, 'html')
# msg.attach(texte_mime)
msg.attach(html_mime)
print("html_mime =" + str(html))
toaddr = str(account_mail)
cc = ['contact@mysy-training.com']
toaddrs = [toaddr] + cc
# msg.attach(MIMEText(open(filename).read()))
with smtplib.SMTP(smtp_address, port) as server:
server.starttls() # Secure the connection
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'envoyer l'email de notification "
'''
Envoie de l'email de suppression du compte utilisateur
'''
def send_user_delete_account(token, account_mail):
try:
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
tomorrow_day = tomorrow.strftime("%A")
msg = MIMEMultipart("alternative")
msg['Subject'] = '[MySy Training Technology] : Suppression de votre'
msg['From'] = 'contact@mysy-training.com'
msg['To'] = str(account_mail)
html = '''
<!DOCTYPE html>
<html>
<body>
<div style="background-color:#eee;padding:0px;text-align:center;width:100%">
<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>
</div>
<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="text-align:center;">
Bonjour
<div style="padding:20px 0px;text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;color#454349;font-size:1.2rem;">
Nous avons reçu une demande de suppression de votre compte <font color="green">MySy-Training</font>.<br/>
Si vous n'etes pas l'auteur de la demande, merci de contacter le service support de MySy.
. <br/>
Le échéant, vous pouvez finaliser la suppression de votre compte en cliquant sur le lien ci-dessous.<br/>
<font color="red">Important : Cette action entrenerait la suppresion definitive de vos information.</font>
<br/>
<div style="background-color:#1962AB;width:20%;text-align:center;margin-left:auto; margin-right:auto;">
<b> <a href="https://www.mysy-training.com/DeleteUserAccount/{objId}" target="_blank" style="color: white;">
Changez de mot de passe
</a>
</b>
</div>
</font>
<br/>
<p>Cordialement<br>
MySy Training Technology<br>
Contact : +337 69 20 39 45<br>
Email : contact@mysy-training.com<br>
</p>
</p>
</div>
</div>
</body>
</html>
'''.format(code=tomorrow_day, objId=token)
html_mime = MIMEText(html, 'html')
# msg.attach(texte_mime)
msg.attach(html_mime)
print("html_mime =" + str(html))
toaddr = str(account_mail)
cc = ['contact@mysy-training.com']
toaddrs = [toaddr] + cc
# msg.attach(MIMEText(open(filename).read()))
with smtplib.SMTP(smtp_address, port) as server:
server.starttls() # Secure the connection
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'envoyer l'email de notification "
'''
Cette fonction envoir n'import quel email avec les varibable :
- recever_email
- objet_mail
- message_mail
'''
def SendGenericEmail(mail_recever=None, mail_object=None, mail_message=None):
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
msg = MIMEMultipart("alternative")
msg['Subject'] = '[MySy Training Technology] : '+str(mail_object)
msg['From'] = MYSY_GV.INTERNAL_MAIL_SENDER
msg['To'] = str(mail_recever)
html = '''
<!DOCTYPE html>
<html>
<body>
<div style="background-color:#eee;padding:0px;text-align:center;width:100%">
<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>
</div>
<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="text-align:center;">
Bonjour
<div style="padding:20px 0px;text-align:center;font-family:Georgia, 'Times New Roman', Times, serif;color#454349;font-size:1.2rem;">
Message de <font color="green">MySy-Training Technology </font>.<br/>
{mymessage}
</div>
</body>
</html> '''.format(mymessage=mail_message)
html_mime = MIMEText(html, 'html')
# msg.attach(texte_mime)
msg.attach(html_mime)
print("html_mime =" + str(html))
toaddr = str(mail_recever)
cc = ['cbalde@mysy-training.com']
toaddrs = [toaddr] + cc
# msg.attach(MIMEText(open(filename).read()))
with smtplib.SMTP(smtp_address, port) as server:
server.starttls() # Secure the connection
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()
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False