import pymongo from pymongo import MongoClient import json from bson import ObjectId import re from datetime import datetime import prj_common as mycommon import secrets import inspect import sys, os import csv import pandas as pd from pymongo import ReturnDocument from math import isnan import GlobalVariable as MYSY_GV import ela_index_bdd_classes as eibdd import email_mgt as email from validate_email import validate_email def email_validation(): try: coll_emails = MYSY_GV.dbname['bdd_email'] cpt = 0 nb_doc = coll_emails.count_documents({'valide':'1', "checked": {"$ne": "1"}}) print(" ### nb_doc = ", nb_doc) for val in coll_emails.find({'valide':'1', "checked": {"$ne": "1"}}): cpt = cpt + 1 if ("email_address" in val.keys()): is_valid = validate_email( email_address=val['email_address'], check_format=True, check_blacklist=True, check_dns=True, dns_timeout=10, check_smtp=True, smtp_timeout=10, smtp_helo_host='smtp.office365.com', smtp_from_address='support@mysy-training.com', smtp_skip_tls=False, smtp_tls_context=None, smtp_debug=False) retval = "" checked_status = "" if( is_valid ): #print(" ### l'adresse ",val['email_address']," est valide ") retval = True checked_status = "1" else: #print(" ### l'adresse ", val['email_address'], " N'EST PAS valide ") retval = False checked_status = "0" mydata = {} mytoday = datetime.today().strftime("%d/%m/%Y") mydata['last_check_date'] = str(mytoday)[0:10] mydata['checked'] = str("1") mydata['checked_status'] = str(checked_status) ret_val = coll_emails.find_one_and_update( {'email_address': str(val['email_address']), 'valide': '1'}, {"$set": mydata}, return_document=ReturnDocument.AFTER ) print(" ### "+str(cpt)+" email traité sur "+str(nb_doc)) return retval, str(cpt)+" adresse email ont été mise à jour " 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 de recuperer la formation" def email_validation_mairies(): try: coll_emails = MYSY_GV.dbname['collect_list_mairies'] cpt = 0 nb_doc = coll_emails.count_documents({'valide': '1', "email_checked": {"$ne": "1"}}) print(" ### nb_doc = ", nb_doc) for val in coll_emails.find({'valide': '1', "checked": {"$ne": "1"}}): cpt = cpt + 1 if ("email" in val.keys()): is_valid = validate_email( email_address=str(val['email']).strip(), check_format=True, check_blacklist=True, check_dns=True, dns_timeout=10, check_smtp=True, smtp_timeout=10, smtp_helo_host='smtp.office365.com', smtp_from_address='support@mysy-training.com', smtp_skip_tls=False, smtp_tls_context=None, smtp_debug=False) retval = "" checked_status = "" if (is_valid): # print(" ### l'adresse ",val['email_address']," est valide ") retval = True checked_status = "1" else: # print(" ### l'adresse ", val['email_address'], " N'EST PAS valide ") retval = False checked_status = "0" mydata = {} mytoday = datetime.today().strftime("%d/%m/%Y") mydata['last_check_date'] = str(mytoday)[0:10] mydata['email_checked'] = str("1") mydata['email_checked_status'] = str(checked_status) ret_val = coll_emails.find_one_and_update( {'email': str(val['email']), 'valide': '1'}, {"$set": mydata}, return_document=ReturnDocument.AFTER ) print(" ### " + str(cpt) + " / " + str(nb_doc)) return retval, str(cpt) + " adresse email ont été mise à jour " 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 de recuperer la formation" def email_validation_hopitaux_ehpad(): try: coll_emails = MYSY_GV.dbname['collect_list_hopitaux_ehpad'] cpt = 0 nb_doc = coll_emails.count_documents({'valide': '1', "email_checked": {"$ne": "1"}}) print(" ### nb_doc = ", nb_doc) for val in coll_emails.find({'valide': '1', "checked": {"$ne": "1"}}): cpt = cpt + 1 if ("email" in val.keys()): is_valid = validate_email( email_address=str(val['email']).strip(), check_format=True, check_blacklist=True, check_dns=True, dns_timeout=10, check_smtp=True, smtp_timeout=10, smtp_helo_host='smtp.office365.com', smtp_from_address='support@mysy-training.com', smtp_skip_tls=False, smtp_tls_context=None, smtp_debug=False) retval = "" checked_status = "" if (is_valid): # print(" ### l'adresse ",val['email_address']," est valide ") retval = True checked_status = "1" else: # print(" ### l'adresse ", val['email_address'], " N'EST PAS valide ") retval = False checked_status = "0" mydata = {} mytoday = datetime.today().strftime("%d/%m/%Y") mydata['last_check_date'] = str(mytoday)[0:10] mydata['email_checked'] = str("1") mydata['email_checked_status'] = str(checked_status) ret_val = coll_emails.find_one_and_update( {'email': str(val['email']), 'valide': '1'}, {"$set": mydata}, return_document=ReturnDocument.AFTER ) print(" ### " + str(cpt) + " / " + str(nb_doc)) return retval, str(cpt) + " adresse email ont été mise à jour " 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 de recuperer la formation" def email_validation_list_pos_bio(): try: coll_emails = MYSY_GV.dbname['collect_list_pos_bio'] cpt = 0 nb_doc = coll_emails.count_documents({'valide': '1', "email_checked": {"$ne": "1"}}) print(" ### nb_doc = ", nb_doc) for val in coll_emails.find({'valide': '1', "checked": {"$ne": "1"}}): cpt = cpt + 1 if ("email" in val.keys()): is_valid = validate_email( email_address=str(val['email']).strip(), check_format=True, check_blacklist=True, check_dns=True, dns_timeout=10, check_smtp=True, smtp_timeout=10, smtp_helo_host='smtp.office365.com', smtp_from_address='support@mysy-training.com', smtp_skip_tls=False, smtp_tls_context=None, smtp_debug=False) retval = "" checked_status = "" if (is_valid): # print(" ### l'adresse ",val['email_address']," est valide ") retval = True checked_status = "1" else: # print(" ### l'adresse ", val['email_address'], " N'EST PAS valide ") retval = False checked_status = "0" mydata = {} mytoday = datetime.today().strftime("%d/%m/%Y") mydata['last_check_date'] = str(mytoday)[0:10] mydata['email_checked'] = str("1") mydata['email_checked_status'] = str(checked_status) ret_val = coll_emails.find_one_and_update( {'email': str(val['email']), 'valide': '1'}, {"$set": mydata}, return_document=ReturnDocument.AFTER ) print(" ### " + str(cpt) + " / " + str(nb_doc)) return retval, str(cpt) + " adresse email ont été mise à jour " 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 de recuperer la formation" import socket import smtplib import re import dns.resolver def test_tab_mail(tab_mail): try: email_address = 'emildqsdssdqdsdie.dacossqqazta@3ds.com' # Step 1: Check email # Check using Regex that an email meets minimum requirements, throw an error if not addressToVerify = email_address match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify) if match == None: print('Bad Syntax in ' + addressToVerify) raise ValueError('Bad Syntax') # Step 2: Getting MX record # Pull domain name from email address domain_name = email_address.split('@')[1] # get the MX record for the domain my_resolver = dns.resolver.Resolver() records = my_resolver.resolve(domain_name, 'MX') mxRecord = records[0].exchange mxRecord = str(mxRecord) print(mxRecord) # Step 3: ping email server # check if the email address exists # Get local server hostname host = socket.gethostname() # SMTP lib setup (use debug level for full output) server = smtplib.SMTP() server.set_debuglevel(0) # SMTP Conversation server.connect(mxRecord) server.helo(host) server.mail('cbalde@mysy-training.com') code, message = server.rcpt(str(addressToVerify)) server.quit() # Assume 250 as Success if code == 250: print('Yes') return True, "OK" else: print('N') return False, "KO" return list_mail = "" if ("list_mail" in tab_mail.keys()): list_mail = str(tab_mail['list_mail']) cpt = 0 val = list_mail print(" list_mail = ", list_mail) is_valid = validate_email( email_address=str(val), check_format=True, check_blacklist=True, check_dns=True, dns_timeout=100, check_smtp=True, smtp_timeout=100, smtp_helo_host='smtp.office365.com', smtp_from_address='support@mysy-training.com', smtp_skip_tls=False, smtp_tls_context=None, smtp_debug=False) retval = "" checked_status = "" if (is_valid): print(" ### l'adresse ",val," est valide ") retval = True else: print(" ### l'adresse ", val, " N'EST PAS valide ") retval = False return retval, str(cpt) + " adresse email ont été mise à jour " 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 de tester le mail" ''' dirty function ''' def dirty(): try: tab = ['a.maisonneuve@ch-montlucon.fr', 'a.notteghem@ch-stquentin.fr', 'adamasambou@live.fr', 'as.aubert@ch-cannes.fr', 'bduquai@gmail.com', 'berdaguerd@gmail.com', 'bnoetinger@yahoo.fr', 'boucherie.gervais@gmail.com', 'boucherie.laiguillon.lh@gmail.com', 'boucherie.piquenot@gmail.com', 'boucheriebeauvais@gmail.com', 'boucheriefouache@gmail.com', 'boucheriesaintvivien@gmail.com', 'breantbaba@gmail.com', 'c.hugues@ch-stquentin.fr', 'canals.cedric@orange.fr', 'caterinallende@yahoo.es', 'catherine.hardy@ch-ariege-couserans.fr', 'cathysalva@live.fr', 'celine.viteau@ch-soissons.fr', 'charcuterieleger@orange.fr', 'charles@closdesvinsdamour.fr', 'chateaunadalhainaut@gmail.com', 'clotdelorigine@gmail.com', 'contact@bioteafull.fr', 'contact@domainepouderoux.fr', 'contact@herboristerie-moderne.fr', 'contact@lesjardinsdemeraude.fr', 'contact@masbecha.com', 'contact@masdenfelix.com ', 'contact@vins-face-b.fr', 'cyril.marais@ch-soissons.fr', 'cyrilfhal@gmail.com', 'daniel.leclerc@gmail.com', 'direction.ehpad.aixeo@hotmail.fr', 'direction.ehpad.rpc@gmail.com', 'direction@ch-hirson.fr', 'direction@chsi-ainay.fr', 'direction@hi-bsav.fr', 'directiongenerale@ch-stquentin.fr', 'dom.ponsgralet@wanadoo.fr', 'domaine.laguerre@orange.fr', 'domainespiaggia@yahoo.com', 'domitienne@outlook.com', 'drh@cas-forcalquier.fr', 'ducrocq.quentin29@gmail.com', 'ehpad.grdbosquet.villerscotterets@wanadoo.fr', 'ehpad@beauregard-residence.fr', 'enidnamag@hotmail.com', 'eric.heyrman@ch-soissons.fr', 'eric.robart@orange.fr', 'etoiledelabergere486@gmail.com', 'f.mezrouh@ch-stquentin.fr', 'flo.moussellous@gmail.com', 'foyer.occ@wanadoo.fr', 'francoise.moreau@hopcobour.net', 'gdesnoix@chsi-ainay.fr', 'helie.boucherie@orange.fr', 'herve.bessiere@gmail.com', 'hopital.saintmaur@gmail.com', 'info.domainegardies@gmail.com', 'info@masllossanes.fr', 'inge.meierhofer@yahoo.fr', 'j.louisy@ch-stquentin.fr', 'jeanmarie.colin@ch-valvert.fr', 'jfdeu@hotmail.com', 'jp.fardeau@cas-forcalquier.fr', 'labergeriedesabeilles@gmail.com', 'lafermedubiosillon@gmail.com', 'lamerblanche66@gmail.com', 'laurent.lemoux@ch-ghsa.fr', 'laurie@lejardinbiodelaurie.fr ', 'lechantdelaterre66@gmail.com', 'lemasaintantoine@gmail.com', 'lepetitsoleilbio66@outlook.fr', 'les.salicaires.vigneron@gmail.com', 'letempsbio@gmail.com', 'lherberie@protonmail.com', 'ljdt66@gmail.com', 'm.saf@ch-guise.fr', 'marc.veuillet@cgd13.fr', 'masdumoutonnoir@gmail.com', 'maugerdominique@hotmail.com', 'mylene.verdu@gmail.com ', 'n.estin@ch-stquentin.fr', 'naliane@chsi-ainay.fr', 'o.ponties@ch-rodez.fr', 'pierre.espejo2@gmail.com', 'pouletbio@live.fr', 'responsable.rh-log@ehpad-mgasquet.fr', 'romain.cochonbio@yahoo.com', 's.bousmaha@ch-stquentin.fr', 's.junker@ch-montlucon.fr', 'sarlavice76@gmail.com', 'sarlmaisoncuvier@gmail.com', 'scealaroqueta@gmail.com', 'sophie.barbier@ch-ghsa.fr', 'thierry.levionnois@orange.fr', 'veroniquedumont42@gmail.com', 'yanisleroux@orange.fr', 'andre.minyemeck@ehpad-conches.fr', 'anne.quinville@armorsante.bzh', 'audrey.licandro@chu-dijon.fr', 'c.bistue@chuzes.fr', 'ca.doussot@cht-ranceemeraude.fr', 'catherine.lahille@gh-portesdeprovence.fr', 'cecile.chalet@chu-nimes.fr', 'cgreslon@ch-bassindethau.fr', 'christian.soubie@ch-libourne.fr', 'contact-stp@hopitaloleron.net', 'contact@ch-edouard-toulouse.fr', 'contact@hopital-vicfezensac.fr', 'contact@nh-navarre.fr', 'd.faivre@chi-hc.fr', 'david.trouchaud@ght-cdn.fr', 'dg.secretariat@ch-perigueux.fr', 'diandra.tijjini@nh-navarre.fr', 'directeur@ch-saint-renan.fr', 'directeur@hopital-murat.fr', 'direction.generale@ch-perrens.fr', 'direction@ch-claudel.fr', 'direction@ch-condom.com', 'direction@gh-portesdeprovence.fr', 'direction@mr-blamont.fr', 'directionfdcmontpon@orange.fr', 'direhpadsudcher@gmail.com', 'e-barde@chu-montpellier.fr', 'ehpad.gracay@orange.fr', 'ehpad.lebrestalou@wanadoo.fr', 'ehpad.lescedres@outlook.fr', 'florie.bideplan@ch-libourne.fr', 'helene.normand@nh-navarre.fr', 'ifsivierzon@ch-vierzon.fr', 'j-lepage@chu-montpellier.fr', 'jean-baptiste.fleury@armorsante.bzh', 'l.brule@ch-hdn.fr', 'lalliot-bironneau@ch-perrens.fr', 'logistique@hlv.fr', 'logistiqueaudincourt@gmail.com', 'magali.luc@chu-nimes.fr', 'maison-retraite@mr-blamont.fr', 'maisonderetraite.montpon@orange.fr', 'marc.jaffuer@ch-libourne.fr', 'mr.la.guerche@wanadoo.fr', 'mrlaignes@wanadoo.fr', 'p.perrot@ch-stmalo.fr', 'personnel@epms-orbec.fr', 'philippe.charre@gh-portesdeprovence.fr', 'ronan.sanquer@chu-brest.fr', 'sdeduit@ch-vierzon.fr', 'sylvie.briend@ch-dinan.fr', 't-veleine@chu-montpellier.fr', 'tyandudcoz@orange.fr'] coll_bio = MYSY_GV.dbname['collect_list_pos_bio'] coll_ehpad = MYSY_GV.dbname['collect_list_hopitaux_ehpad'] coll_boucherie = MYSY_GV.dbname['collect_list_boucherie'] for val in tab : for ret1 in coll_bio.find({'email':val}): if ("email" in ret1.keys()): print( "'Point de vente BIO', '",ret1['email'], "' => '",ret1['raison_sociale'], "' => '", ret1['adress'], "'=> '", ret1['tel']+"'") for ret2 in coll_ehpad.find({'email':val}): if ("email" in ret2.keys()): print( "'EHPAD & HOPITAUX', '",ret2['email'], "'=> '",ret2['raison_sociale'], "' => '", ret2['adresse'], "'=>' ", ret2['tel']+"'") for ret3 in coll_boucherie.find({'email':val}): if ("email" in ret3.keys()): print("'BOUCHERIE', '", ret3['email'], "'=> '",ret3['raison_sociale'], "' => '---' => '", ret3['tel']+"'") return True, "ok" 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 de tester le mail"