29/07/2024 - 21h
parent
8dfbd7e8a0
commit
a5b48624ad
|
@ -1,12 +1,10 @@
|
|||
<?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="26/07/2024 - 12h">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="29/07/2024 - 12h">
|
||||
<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$/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" />
|
||||
|
@ -76,13 +74,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00311" summary="sdsqq">
|
||||
<created>1716483578232</created>
|
||||
<option name="number" value="00311" />
|
||||
<option name="presentableId" value="LOCAL-00311" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1716483578233</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00312" summary="ss">
|
||||
<created>1716568731554</created>
|
||||
<option name="number" value="00312" />
|
||||
|
@ -419,7 +410,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1721997046282</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="360" />
|
||||
<task id="LOCAL-00360" summary="29/07/2024 - 12h">
|
||||
<created>1722251969652</created>
|
||||
<option name="number" value="00360" />
|
||||
<option name="presentableId" value="LOCAL-00360" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1722251969653</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="361" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -461,7 +459,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="12/06/2024 - 21h30" />
|
||||
<MESSAGE value="15/06/2024 - 21h30" />
|
||||
<MESSAGE value="17/06/2024 - 21h30" />
|
||||
<MESSAGE value="18/06/2024 - 21h30" />
|
||||
|
@ -486,6 +483,7 @@
|
|||
<MESSAGE value="21/07/2024 - 12h" />
|
||||
<MESSAGE value="23/07/2024 - 12h" />
|
||||
<MESSAGE value="26/07/2024 - 12h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="26/07/2024 - 12h" />
|
||||
<MESSAGE value="29/07/2024 - 12h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="29/07/2024 - 12h" />
|
||||
</component>
|
||||
</project>
|
1255
Log/log_file.log
1255
Log/log_file.log
File diff suppressed because it is too large
Load Diff
199
email_mgt.py
199
email_mgt.py
|
@ -3102,6 +3102,11 @@ 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."
|
||||
|
||||
"""
|
||||
Verifier que le format list_email_bcc est valide
|
||||
"""
|
||||
|
@ -3120,6 +3125,9 @@ 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."
|
||||
|
||||
"""
|
||||
Verifier la validité des emails de destinataire
|
||||
|
@ -3149,8 +3157,8 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
if( is_valide_email_in_related_collection < 1 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'adresse email '" + str(email_dest) + "' est invalide (2) ")
|
||||
return False, " L'adresse email '" + str(email_dest) + "' est invalide (2) "
|
||||
3]) + " L'adresse email '" + str(email_dest) + "' existe pas dans le système ")
|
||||
return False, " L'adresse email '" + str(email_dest) + "'existe pas dans le système "
|
||||
|
||||
is_valide_email_in_related_collection_data = MYSY_GV.dbname[str(related_collection)].find_one(
|
||||
{"email": str(email_dest),
|
||||
|
@ -3163,7 +3171,17 @@ 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."
|
||||
|
||||
|
||||
|
||||
# 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. "
|
||||
|
||||
tab_saved_file_full_path = []
|
||||
for file in tab_files:
|
||||
status, saved_file_full_path = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
||||
|
@ -3173,6 +3191,22 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
|
||||
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'])
|
||||
|
@ -3196,6 +3230,8 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
Envoie proprement-dit des emails
|
||||
"""
|
||||
for user_id in tab_related_collection_id:
|
||||
|
||||
|
||||
user_related_collection_data = MYSY_GV.dbname[str(related_collection)].find_one(
|
||||
{"_id": ObjectId(str(user_id)),
|
||||
'valide': '1',
|
||||
|
@ -3230,6 +3266,36 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
|
||||
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'] = 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'] = email
|
||||
|
||||
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
|
||||
|
||||
'''
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = partner_SMTP_COUNT_From_User
|
||||
|
@ -3237,6 +3303,11 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
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
|
||||
|
@ -3248,6 +3319,11 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
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
|
||||
|
@ -3255,7 +3331,126 @@ def Prepare_and_Send_Email_From_Front(tab_files, Folder, diction):
|
|||
|
||||
smtpserver.close()
|
||||
|
||||
|
||||
'''
|
||||
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)
|
||||
|
||||
"""
|
||||
field_list = ['token', 'list_email_dest', 'list_email_cc', 'list_email_bcc', 'email_corps', 'related_collection',
|
||||
'email_sujet']
|
||||
incom_keys = diction.keys()
|
||||
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " - Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, "Impossible de créer le stagiaire. Toutes les informations fournies ne sont pas valables"
|
||||
|
||||
field_list_obligatoire = ['token', 'list_email_dest', 'related_collection',
|
||||
'email_sujet', 'email_corps']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
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
|
||||
|
||||
smtpserver = None
|
||||
|
||||
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']
|
||||
tab_files_to_attache_to_mail = diction['tab_files_to_attache_to_mail']
|
||||
email_sujet = diction['email_sujet']
|
||||
html_mime = diction['html_mime']
|
||||
email = diction['email']
|
||||
|
||||
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
|
||||
tab_email_bcc.append(str(my_partner['email']))
|
||||
|
||||
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()
|
||||
|
||||
return True, " Les emails ont été correctement envoyés"
|
||||
|
||||
|
|
Loading…
Reference in New Issue