30/07/2024 - 12h
parent
a5b48624ad
commit
b5d25d91eb
|
@ -1,10 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="29/07/2024 - 12h">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="29/07/2024 - 21h">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/email_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -74,13 +77,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00312" summary="ss">
|
||||
<created>1716568731554</created>
|
||||
<option name="number" value="00312" />
|
||||
<option name="presentableId" value="LOCAL-00312" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1716568731554</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00313" summary="gdfgdf">
|
||||
<created>1716732752643</created>
|
||||
<option name="number" value="00313" />
|
||||
|
@ -417,7 +413,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1722251969653</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="361" />
|
||||
<task id="LOCAL-00361" summary="29/07/2024 - 21h">
|
||||
<created>1722279870243</created>
|
||||
<option name="number" value="00361" />
|
||||
<option name="presentableId" value="LOCAL-00361" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1722279870244</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="362" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -459,7 +462,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="15/06/2024 - 21h30" />
|
||||
<MESSAGE value="17/06/2024 - 21h30" />
|
||||
<MESSAGE value="18/06/2024 - 21h30" />
|
||||
<MESSAGE value="ss" />
|
||||
|
@ -484,6 +486,7 @@
|
|||
<MESSAGE value="23/07/2024 - 12h" />
|
||||
<MESSAGE value="26/07/2024 - 12h" />
|
||||
<MESSAGE value="29/07/2024 - 12h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="29/07/2024 - 12h" />
|
||||
<MESSAGE value="29/07/2024 - 21h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="29/07/2024 - 21h" />
|
||||
</component>
|
||||
</project>
|
|
@ -570,7 +570,8 @@ Pour mettre en place un système de configuration global, on va definir les vale
|
|||
"""
|
||||
PARTNER_BASE_CONFIG_NAME = ['tva', 'smtp_server', 'smtp_user', 'smtp_user_pwd', 'smtp_count_from_name',
|
||||
'smtp_count_port', 'partner_smtp', 'partner_jour_heure', 'nb_relance_auto',
|
||||
'relance_auto', 'frequence_relance_auto', 'session_warning', 'session_warning_lead_time']
|
||||
'relance_auto', 'frequence_relance_auto', 'session_warning', 'session_warning_lead_time',
|
||||
'recyclage_warning', 'recyclage_warning_lead_time']
|
||||
|
||||
|
||||
"""
|
||||
|
@ -741,6 +742,11 @@ Completude des etapes d'une session de formation : "statut_completude"
|
|||
|
||||
"""
|
||||
Gestion du module d'envoie d'email
|
||||
les 'related_collection' sont : ['inscription', 'apprenant', 'contact']
|
||||
les 'related_collection' sont : ['inscription', 'apprenant', 'contact', 'nointernalcontact']
|
||||
"""
|
||||
EMAIL_DEST_RELATED_COLLECTION = ['inscription', 'apprenant', 'contact']
|
||||
EMAIL_DEST_RELATED_COLLECTION = ['inscription', 'apprenant', 'contact', 'nointernalcontact']
|
||||
|
||||
EMAIL_MAX_DESTINAIRE = 30
|
||||
EMAIL_MAX_CC = 10
|
||||
EMAIL_MAX_BCC = 10
|
||||
EMAIL_MAX_PJ = 5
|
|
@ -7290,6 +7290,37 @@ def Get_Statgaire_List_Partner_with_filter(diction):
|
|||
partner_recid = my_partner['recid']
|
||||
|
||||
|
||||
"""
|
||||
30/07/2024 - Pour la gestion du recyclage, recuperer les paramettres du partner dans la collection "base_partner_setup"
|
||||
- recyclage_warning
|
||||
- recyclage_warning_lead_time
|
||||
"""
|
||||
recyclage_warning = "0"
|
||||
recyclage_warning_lead_time = "0"
|
||||
partner_base_setup_recyclage_warning = MYSY_GV.dbname['base_partner_setup'].find_one({"config_name":'recyclage_warning',
|
||||
'valide':'1', 'locked':'0',
|
||||
'partner_owner_recid':my_partner['recid']})
|
||||
|
||||
if( partner_base_setup_recyclage_warning and "config_value" in partner_base_setup_recyclage_warning.keys() ):
|
||||
recyclage_warning = partner_base_setup_recyclage_warning['config_value']
|
||||
|
||||
|
||||
if( recyclage_warning == "1"):
|
||||
partner_base_setup_recyclage_warning_lead_time = MYSY_GV.dbname['base_partner_setup'].find_one(
|
||||
{"config_name": 'recyclage_warning_lead_time',
|
||||
'valide': '1', 'locked': '0',
|
||||
'partner_owner_recid': my_partner['recid']})
|
||||
|
||||
if (partner_base_setup_recyclage_warning_lead_time and "config_value" in partner_base_setup_recyclage_warning_lead_time.keys()):
|
||||
recyclage_warning_lead_time = str(mycommon.tryInt(str(partner_base_setup_recyclage_warning_lead_time['config_value'])))
|
||||
|
||||
|
||||
|
||||
|
||||
print(" #### recyclage_warning = ", str(recyclage_warning), " ### recyclage_warning_lead_time = ", str(recyclage_warning_lead_time))
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Etape 1 : si on a le champ 'code session' saisie par l'utilisateur,
|
||||
|
@ -7317,7 +7348,7 @@ def Get_Statgaire_List_Partner_with_filter(diction):
|
|||
for val in MYSY_GV.dbname['session_formation'].find(qry_list_session_id):
|
||||
list_session_id.append(str(val['_id']))
|
||||
|
||||
print(" ### liste des Id des sessions eligible list_session_id = ", list_session_id)
|
||||
#print(" ### liste des Id des sessions eligible list_session_id = ", list_session_id)
|
||||
filt_session_id = {'session_id': {'$in': list_session_id, }}
|
||||
|
||||
filt_class_title = {}
|
||||
|
@ -7401,7 +7432,7 @@ def Get_Statgaire_List_Partner_with_filter(diction):
|
|||
|
||||
|
||||
]
|
||||
print("#### Get_Statgaire_List_Partner_with_filter laa 01 : query = ", query)
|
||||
#print("#### Get_Statgaire_List_Partner_with_filter laa 01 : query = ", query)
|
||||
RetObject = []
|
||||
cpt = 0
|
||||
for retVal in MYSY_GV.dbname['inscription'].aggregate(query):
|
||||
|
@ -7614,9 +7645,10 @@ def Get_Statgaire_List_Partner_with_filter(diction):
|
|||
val['class_recyclage_delai'] = ""
|
||||
val['class_recyclage_periodicite'] = ""
|
||||
val['nb_jour_avant_recyclage'] = ""
|
||||
val['warning_recyclage'] = "0"
|
||||
|
||||
if( "recyclage_managed" not in retVal.keys() or retVal['recyclage_managed'] != "1"):
|
||||
|
||||
if(retVal['status'] == "1" and ("recyclage_managed" not in retVal.keys() or retVal['recyclage_managed'] != "1") ):
|
||||
|
||||
if ("recyclage_delai" in retVal['myclass_collection'][0].keys()):
|
||||
val['class_recyclage_delai'] = retVal['myclass_collection'][0]['recyclage_delai']
|
||||
|
@ -7644,6 +7676,10 @@ def Get_Statgaire_List_Partner_with_filter(diction):
|
|||
local_delta = session_date_debut_datetime - mytoday_datetime
|
||||
val['nb_jour_avant_recyclage'] = str(local_delta.days)
|
||||
|
||||
if( recyclage_warning == "1" ):
|
||||
if( local_delta.days < mycommon.tryInt(str(recyclage_warning_lead_time)) ):
|
||||
val['warning_recyclage'] = "1"
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
@ -7734,10 +7770,9 @@ def Get_Statgaire_List_Partner_with_filter(diction):
|
|||
|
||||
|
||||
|
||||
|
||||
RetObject.append(mycommon.JSONEncoder().encode(val))
|
||||
|
||||
|
||||
print(" ### RetObject = ", str(RetObject))
|
||||
return True, RetObject
|
||||
|
||||
except Exception as e:
|
||||
|
|
4305
Log/log_file.log
4305
Log/log_file.log
File diff suppressed because it is too large
Load Diff
310
email_mgt.py
310
email_mgt.py
|
@ -3102,10 +3102,9 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
str(inspect.stack()[0][3]) + " L'adresse email en CC '" + str(email_cc) + "' est invalide ")
|
||||
return False, "L'adresse email en CC '" + str(email_cc) + "' est invalide"
|
||||
|
||||
|
||||
if (len(tab_email_cc) > 10):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de 10 emails en copie.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de 10 emails en copie."
|
||||
if (len(tab_email_cc) > MYSY_GV.EMAIL_MAX_CC):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de " + str(MYSY_GV.EMAIL_MAX_BCC) + " emails en copie.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de " + str(MYSY_GV.EMAIL_MAX_BCC) + " emails en copie."
|
||||
|
||||
"""
|
||||
Verifier que le format list_email_bcc est valide
|
||||
|
@ -3125,12 +3124,16 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
str(inspect.stack()[0][3]) + " L'adresse email en BCC '" + str(email_bcc) + "' est invalide ")
|
||||
return False, "L'adresse email en BCC '" + str(email_bcc) + "' est invalide"
|
||||
|
||||
if (len(tab_email_bcc) > 10):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de 10 emails en copie-cachée.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de 10 emails en copie-cachée."
|
||||
|
||||
if (len(tab_email_bcc) > MYSY_GV.EMAIL_MAX_BCC):
|
||||
mycommon.myprint(
|
||||
"Vous ne pouvez pas envoyer plus de " + str(MYSY_GV.EMAIL_MAX_BCC) + " emails en copie-cachée.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de " + str(
|
||||
MYSY_GV.EMAIL_MAX_BCC) + " emails en copie-cachée."
|
||||
|
||||
"""
|
||||
Verifier la validité des emails de destinataire
|
||||
Verifier la validité des emails de destinataire.
|
||||
Si et SEULEMENT SI "related_collection" != "no_contact"
|
||||
"""
|
||||
tab_related_collection_id = []
|
||||
tab_email_dest = ""
|
||||
|
@ -3171,16 +3174,18 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
|
||||
#print(" ### la liste _id des destinataire est ", str(tab_related_collection_id))
|
||||
|
||||
if(len(tab_related_collection_id) > 20 ):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de 20 emails à la fois.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de 20 emails à la fois."
|
||||
if (len(tab_email_dest) > MYSY_GV.EMAIL_MAX_DESTINAIRE):
|
||||
mycommon.myprint(
|
||||
"Vous ne pouvez pas envoyer plus de " + str(MYSY_GV.EMAIL_MAX_DESTINAIRE) + " emails à la fois.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de " + str(
|
||||
MYSY_GV.EMAIL_MAX_DESTINAIRE) + " emails à la fois."
|
||||
|
||||
|
||||
|
||||
# Sauvegarde des fichiers joints depuis le front
|
||||
if (len(tab_files) > 5 ):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de 5 pièces jointes.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de 5 pièces jointes. "
|
||||
if (len(tab_files) > MYSY_GV.EMAIL_MAX_PJ):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de " + str(MYSY_GV.EMAIL_MAX_PJ) + " pièces jointes.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de " + str(MYSY_GV.EMAIL_MAX_PJ) + " pièces jointes. "
|
||||
|
||||
tab_saved_file_full_path = []
|
||||
for file in tab_files:
|
||||
|
@ -3289,50 +3294,6 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
|
||||
cpt_email_envoye = cpt_email_envoye + 1
|
||||
|
||||
'''
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = partner_SMTP_COUNT_From_User
|
||||
msg['Cc'] = ", ".join(tab_email_cc)
|
||||
msg['Bcc'] = ", ".join(tab_email_bcc)
|
||||
msg['Subject'] = email_sujet
|
||||
msg['to'] = str(email)
|
||||
|
||||
# Attacher l'eventuelle pièces jointes
|
||||
for myfile in tab_files_to_attache_to_mail:
|
||||
msg.attach(myfile['attached_file'])
|
||||
|
||||
val = smtpserver.send_message(msg)
|
||||
print(" Email a envoyé " + str(email))
|
||||
cpt_email_envoye = cpt_email_envoye + 1
|
||||
|
||||
else:
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['Cc'] = ", ".join(tab_email_cc)
|
||||
msg['Bcc'] = ", ".join(tab_email_bcc)
|
||||
msg['Subject'] = email_sujet
|
||||
msg['to'] = str(email)
|
||||
|
||||
# Attacher l'eventuelle pièces jointes
|
||||
for myfile in tab_files_to_attache_to_mail:
|
||||
msg.attach(myfile['attached_file'])
|
||||
|
||||
val = smtpserver.send_message(msg)
|
||||
print(" Email a envoyé " + str(email))
|
||||
cpt_email_envoye = cpt_email_envoye + 1
|
||||
|
||||
|
||||
smtpserver.close()
|
||||
|
||||
|
||||
'''
|
||||
print(" NB_email envoyé = ", cpt_email_envoye)
|
||||
return True, " Les emails ont été correctement envoyés"
|
||||
|
||||
|
@ -3343,13 +3304,14 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
|
||||
|
||||
"""
|
||||
Envoi d'un email email individuel
|
||||
Cette fonction envoie des email pour des destinataires qui ne sont pas connus de mysy.
|
||||
donc impossible d'utiliser les tag comme les nom et prenom etc
|
||||
"""
|
||||
def send_invidual_email(diction):
|
||||
def Prepare_and_Send_Email_From_Front_For_Unknown_Contact(tab_files, Folder, diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
|
||||
field_list = ['token', 'list_email_dest', 'list_email_cc', 'list_email_bcc', 'email_corps', 'related_collection',
|
||||
'email_sujet']
|
||||
incom_keys = diction.keys()
|
||||
|
@ -3369,7 +3331,230 @@ def send_invidual_email(diction):
|
|||
str(inspect.stack()[0][
|
||||
3]) + " La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " La valeur '" + val + "' n'est pas presente dans liste"
|
||||
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
"""
|
||||
Verifier la validité "related_collection"
|
||||
"""
|
||||
related_collection = str(diction['related_collection']).strip().lower()
|
||||
if(related_collection not in MYSY_GV.EMAIL_DEST_RELATED_COLLECTION ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Le champ 'related_collection' est invalide ")
|
||||
return False, " Le champ 'related_collection' est invalide "
|
||||
|
||||
local_partner_owner_recid = "partner_owner_recid"
|
||||
if (related_collection == "contact"):
|
||||
local_partner_owner_recid = "partner_recid"
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Gestion du sujet :
|
||||
On le tronc à 200 caractère max
|
||||
"""
|
||||
email_sujet = ""
|
||||
if(len(str(diction['email_sujet'])) > 200 ):
|
||||
email_sujet = str(diction['email_sujet'])[0:200]
|
||||
else:
|
||||
email_sujet = str(diction['email_sujet'])
|
||||
|
||||
|
||||
"""
|
||||
Verifier que le format list_email_cc est valide
|
||||
"""
|
||||
tab_email_cc = ""
|
||||
if ("list_email_cc" in diction.keys()):
|
||||
if diction['list_email_cc']:
|
||||
tab_email_cc = diction['list_email_cc']
|
||||
|
||||
tab_email_cc = str(tab_email_cc).split(",")
|
||||
for email_cc in tab_email_cc:
|
||||
if (email_cc):
|
||||
if (mycommon.isEmailValide(str(email_cc)) is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'adresse email en CC '" + str(email_cc) + "' est invalide ")
|
||||
return False, "L'adresse email en CC '" + str(email_cc) + "' est invalide"
|
||||
|
||||
|
||||
if (len(tab_email_cc) > MYSY_GV.EMAIL_MAX_CC):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de "+str(MYSY_GV.EMAIL_MAX_BCC)+" emails en copie.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de "+str(MYSY_GV.EMAIL_MAX_BCC)+" emails en copie."
|
||||
|
||||
"""
|
||||
Verifier que le format list_email_bcc est valide
|
||||
"""
|
||||
tab_email_bcc = ""
|
||||
if ("list_email_bcc" in diction.keys()):
|
||||
if diction['list_email_bcc']:
|
||||
tab_email_bcc = diction['list_email_bcc']
|
||||
|
||||
|
||||
tab_email_bcc = str(tab_email_bcc).split(",")
|
||||
for email_bcc in tab_email_bcc:
|
||||
if (email_bcc):
|
||||
|
||||
if (mycommon.isEmailValide(str(email_bcc)) is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'adresse email en BCC '" + str(email_bcc) + "' est invalide ")
|
||||
return False, "L'adresse email en BCC '" + str(email_bcc) + "' est invalide"
|
||||
|
||||
if (len(tab_email_bcc) > MYSY_GV.EMAIL_MAX_BCC):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de "+str(MYSY_GV.EMAIL_MAX_BCC)+" emails en copie-cachée.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de "+str(MYSY_GV.EMAIL_MAX_BCC)+" emails en copie-cachée."
|
||||
|
||||
"""
|
||||
Verifier la validité des emails de destinataire.
|
||||
Si et SEULEMENT SI "related_collection" != "no_contact"
|
||||
"""
|
||||
tab_related_collection_id = []
|
||||
tab_email_dest = ""
|
||||
if ("list_email_dest" in diction.keys()):
|
||||
if diction['list_email_dest']:
|
||||
tab_email_dest = diction['list_email_dest']
|
||||
|
||||
tab_email_dest = str(tab_email_dest).split(",")
|
||||
for email_dest in tab_email_dest:
|
||||
if( email_dest ):
|
||||
if (mycommon.isEmailValide(str(email_dest)) is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'adresse email '" + str(email_dest) + "' est invalide ")
|
||||
return False, "L'adresse email '" + str(email_dest) + "' est invalide"
|
||||
|
||||
|
||||
|
||||
|
||||
#print(" ### la liste _id des destinataire est ", str(tab_related_collection_id))
|
||||
|
||||
if(len(tab_email_dest) > MYSY_GV.EMAIL_MAX_DESTINAIRE ):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de "+str(MYSY_GV.EMAIL_MAX_DESTINAIRE)+" emails à la fois.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de "+str(MYSY_GV.EMAIL_MAX_DESTINAIRE)+" emails à la fois."
|
||||
|
||||
|
||||
|
||||
# Sauvegarde des fichiers joints depuis le front
|
||||
if (len(tab_files) > MYSY_GV.EMAIL_MAX_PJ ):
|
||||
mycommon.myprint("Vous ne pouvez pas envoyer plus de "+str(MYSY_GV.EMAIL_MAX_PJ)+" pièces jointes.")
|
||||
return False, "Vous ne pouvez pas envoyer plus de "+str(MYSY_GV.EMAIL_MAX_PJ)+" pièces jointes. "
|
||||
|
||||
tab_saved_file_full_path = []
|
||||
for file in tab_files:
|
||||
status, saved_file_full_path = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
||||
if (status is False):
|
||||
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
||||
return False, "Impossible de récupérer correctement le fichier à importer"
|
||||
|
||||
tab_saved_file_full_path.append(saved_file_full_path)
|
||||
|
||||
# Traitement de l'eventuel fichier joint
|
||||
tab_files_to_attache_to_mail = []
|
||||
for saved_file in tab_saved_file_full_path:
|
||||
|
||||
|
||||
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
||||
file_to_attache_to_mail.set_payload(open(saved_file, "rb").read())
|
||||
|
||||
encoders.encode_base64(file_to_attache_to_mail)
|
||||
file_to_attache_to_mail.add_header('Content-Disposition',
|
||||
'attachment; filename="{0}"'.format(os.path.basename(saved_file)))
|
||||
|
||||
new_node = {"attached_file": file_to_attache_to_mail}
|
||||
tab_files_to_attache_to_mail.append(new_node)
|
||||
|
||||
|
||||
# Recuperation des donnes SMTP
|
||||
local_stpm_status, partner_SMTP_COUNT_smtpsrv, partner_own_smtp_value, partner_SMTP_COUNT_password, partner_SMTP_COUNT_user, partner_SMTP_COUNT_From_User, partner_SMTP_COUNT_port = mycommon.Get_Partner_SMTP_Param(
|
||||
my_partner['recid'])
|
||||
|
||||
if (local_stpm_status is False):
|
||||
return local_stpm_status, partner_own_smtp_value
|
||||
|
||||
smtpserver = None
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
||||
else:
|
||||
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
||||
cpt_email_envoye = 0
|
||||
|
||||
"""
|
||||
Envoie proprement-dit des emails
|
||||
"""
|
||||
for local_email_dest in tab_email_dest:
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
|
||||
|
||||
node = {}
|
||||
node['nom'] = ""
|
||||
node['prenom'] = ""
|
||||
body = {
|
||||
"params": node,
|
||||
}
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
contenu_doc_Template = jinja2.Template(str(diction['email_corps']))
|
||||
|
||||
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||||
|
||||
html_mime = MIMEText(sourceHtml, 'html')
|
||||
|
||||
|
||||
tab_email_bcc.append(str(my_partner['email']))
|
||||
|
||||
local_diction = {}
|
||||
local_diction['token'] = diction['token']
|
||||
local_diction['partner_own_smtp_value'] = partner_own_smtp_value
|
||||
local_diction['partner_SMTP_COUNT_smtpsrv'] = partner_SMTP_COUNT_smtpsrv
|
||||
local_diction['partner_SMTP_COUNT_port'] = partner_SMTP_COUNT_port
|
||||
local_diction['user_id'] = ""
|
||||
local_diction['related_collection'] = related_collection
|
||||
local_diction['partner_SMTP_COUNT_From_User'] = partner_SMTP_COUNT_From_User
|
||||
local_diction['tab_email_cc'] = tab_email_cc
|
||||
local_diction['tab_email_bcc'] = tab_email_bcc
|
||||
local_diction['tab_files_to_attache_to_mail'] = tab_files_to_attache_to_mail
|
||||
local_diction['email_sujet'] = email_sujet
|
||||
local_diction['html_mime'] = html_mime
|
||||
local_diction['email'] = str(local_email_dest)
|
||||
|
||||
local_status, local_retval = send_invidual_email (local_diction)
|
||||
if( local_status is False ):
|
||||
return local_status, local_retval
|
||||
|
||||
cpt_email_envoye = cpt_email_envoye + 1
|
||||
|
||||
print(" NB_email envoyé = ", cpt_email_envoye)
|
||||
return True, " Les emails ont été correctement envoyés"
|
||||
|
||||
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 les emails "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Envoi d'un email email individuel
|
||||
"""
|
||||
def send_invidual_email(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
|
@ -3384,8 +3569,7 @@ def send_invidual_email(diction):
|
|||
partner_own_smtp_value = diction['partner_own_smtp_value']
|
||||
partner_SMTP_COUNT_smtpsrv = diction['partner_SMTP_COUNT_smtpsrv']
|
||||
partner_SMTP_COUNT_port = diction['partner_SMTP_COUNT_port']
|
||||
user_id = diction['user_id']
|
||||
related_collection = diction['related_collection']
|
||||
|
||||
partner_SMTP_COUNT_From_User = diction['partner_SMTP_COUNT_From_User']
|
||||
tab_email_cc = diction['tab_email_cc']
|
||||
tab_email_bcc = diction['tab_email_bcc']
|
||||
|
|
28
main.py
28
main.py
|
@ -10529,7 +10529,8 @@ def DeleteImage_Partner_Product():
|
|||
|
||||
|
||||
"""
|
||||
API qui permet d'envoyer des emails generés depuis le front
|
||||
API qui permet d'envoyer des emails generés depuis le front pour les contact connus
|
||||
(possibilité d'utiliser des tags dans le modele emails)
|
||||
"""
|
||||
@app.route('/myclass/api/Prepare_and_Send_Email_From_Front/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
|
@ -10551,6 +10552,31 @@ def Prepare_and_Send_Email_From_Front():
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API qui permet d'envoyer des emails generés depuis le front pour les contact INCONNU
|
||||
(IMPOSSIBLE d'utiliser des tags dans le modele emails)
|
||||
"""
|
||||
@app.route('/myclass/api/Prepare_and_Send_Email_From_Front_For_Unknown_Contact/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Prepare_and_Send_Email_From_Front_For_Unknown_Contact():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Prepare_and_Send_Email_From_Front_For_Unknown_Contact payload = ",payload)
|
||||
file = []
|
||||
tab_files = []
|
||||
if request.method == 'POST':
|
||||
# Create variable for uploaded file
|
||||
tab_files = []
|
||||
for tmp in request.files.getlist("File"):
|
||||
tab_files.append(tmp)
|
||||
|
||||
status, retval = emails.Prepare_and_Send_Email_From_Front_For_Unknown_Contact(tab_files, MYSY_GV.TEMPORARY_DIRECTORY_V2, payload)
|
||||
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
context = SSL.Context(SSL.SSLv23_METHOD)
|
||||
|
|
Loading…
Reference in New Issue