Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| script_de_generation_de_template_mail_outlook [2025/10/22 14:52] – créée superadmin | script_de_generation_de_template_mail_outlook [2025/10/30 11:54] (Version actuelle) – superadmin | ||
|---|---|---|---|
| Ligne 2: | Ligne 2: | ||
| À adapter en fonction du contexte. Les templates de base doivent être au format HTML et contenir les variables sous la forme {variable}. | À adapter en fonction du contexte. Les templates de base doivent être au format HTML et contenir les variables sous la forme {variable}. | ||
| + | |||
| + | Extensions requises : '' | ||
| <code python> | <code python> | ||
| import win32com.client as win32 | import win32com.client as win32 | ||
| + | import requests | ||
| + | import json | ||
| + | |||
| + | #URL du webhook | ||
| + | webhook_url = ' | ||
| #fonction menu | #fonction menu | ||
| Ligne 11: | Ligne 18: | ||
| print(" | print(" | ||
| print(" | print(" | ||
| + | print(" | ||
| + | print(" | ||
| choix = input(" | choix = input(" | ||
| Ligne 17: | Ligne 26: | ||
| elif choix == ' | elif choix == ' | ||
| fin_incident_notif() | fin_incident_notif() | ||
| + | elif choix == ' | ||
| + | client1_incident_notif() | ||
| + | elif choix == ' | ||
| + | client1_fin_incident_notif() | ||
| else: | else: | ||
| print(" | print(" | ||
| Ligne 23: | Ligne 36: | ||
| def incident_notif(): | def incident_notif(): | ||
| # Demande des infos à l' | # Demande des infos à l' | ||
| - | destinatairesprincipaux = input(" | + | destinatairesprincipaux = input(" |
| destinatairessecondaires = input(" | destinatairessecondaires = input(" | ||
| client = input(" | client = input(" | ||
| Ligne 31: | Ligne 44: | ||
| duree = input(" | duree = input(" | ||
| equipement = input(" | equipement = input(" | ||
| - | incident_ref = input(" | + | incident_ref = input(" |
| impact = input(" | impact = input(" | ||
| Ligne 57: | Ligne 70: | ||
| next_update = input(" | next_update = input(" | ||
| incident_owner = input(" | incident_owner = input(" | ||
| + | |||
| + | # Demande si on doit faire une notif mattermost ou non | ||
| + | notif_equipe = input(" | ||
| + | |||
| + | if notif_equipe == ' | ||
| + | notif_mattermost(webhook_url, | ||
| # Concatenne les variables | # Concatenne les variables | ||
| sujetmail = " | sujetmail = " | ||
| - | destinataires = "security.incident-mngt@orange.com; | + | destinataires = "test@test.fr;" + destinatairesprincipaux |
| - | destinatairescopie = "itd-soc-france@orange.com; | + | destinatairescopie = "test@test.fr;" + destinatairessecondaires |
| # Charger le template HTML depuis un fichier externe | # Charger le template HTML depuis un fichier externe | ||
| Ligne 99: | Ligne 118: | ||
| def fin_incident_notif(): | def fin_incident_notif(): | ||
| # Demande des infos à l' | # Demande des infos à l' | ||
| - | destinatairesprincipaux = input(" | + | destinatairesprincipaux = input(" |
| destinatairessecondaires = input(" | destinatairessecondaires = input(" | ||
| client = input(" | client = input(" | ||
| Ligne 107: | Ligne 126: | ||
| duree = input(" | duree = input(" | ||
| equipement = input(" | equipement = input(" | ||
| - | incident_ref = input(" | + | incident_ref = input(" |
| impact = input(" | impact = input(" | ||
| Ligne 133: | Ligne 152: | ||
| next_update = input(" | next_update = input(" | ||
| incident_owner = input(" | incident_owner = input(" | ||
| + | |||
| + | # Demande si on doit faire une notif mattermost ou non | ||
| + | notif_equipe = input(" | ||
| + | |||
| + | if notif_equipe == ' | ||
| + | notif_fin_mattermost(webhook_url, | ||
| # Concatenne les variables | # Concatenne les variables | ||
| sujetmail = " | sujetmail = " | ||
| - | destinataires = "security.incident-mngt@orange.com; | + | destinataires = "test@test.fr;" + destinatairesprincipaux |
| - | destinatairescopie = "itd-soc-france@orange.com; | + | destinatairescopie = "test@test.fr;" + destinatairessecondaires |
| # Charger le template HTML depuis un fichier externe | # Charger le template HTML depuis un fichier externe | ||
| Ligne 161: | Ligne 186: | ||
| next_update=next_update, | next_update=next_update, | ||
| incident_owner=incident_owner | incident_owner=incident_owner | ||
| + | ) | ||
| + | |||
| + | # Créer et afficher le mail Outlook | ||
| + | outlook = win32.Dispatch(' | ||
| + | mail = outlook.CreateItem(0) | ||
| + | mail.Subject = sujetmail | ||
| + | mail.To = destinataires | ||
| + | mail.CC = destinatairescopie | ||
| + | mail.HTMLBody = contenu_html | ||
| + | mail.Display() | ||
| + | |||
| + | #fonction notification d' | ||
| + | def client1_incident_notif(): | ||
| + | # Demande des infos à l' | ||
| + | destinatairessecondaires = input(" | ||
| + | perimetre = input(" | ||
| + | description = input(" | ||
| + | start_date = input(" | ||
| + | start_time = input(" | ||
| + | equipement = input(" | ||
| + | incident_ref = input(" | ||
| + | impact = input(" | ||
| + | statut = input(" | ||
| + | client = " | ||
| + | |||
| + | # Demande si on doit faire une notif mattermost ou non | ||
| + | notif_equipe = input(" | ||
| + | |||
| + | if notif_equipe == ' | ||
| + | notif_mattermost_client1(webhook_url, | ||
| + | |||
| + | # Concatenne les variables | ||
| + | sujetmail = " | ||
| + | destinataires = " | ||
| + | destinatairescopie = " | ||
| + | |||
| + | # Charger le template HTML depuis un fichier externe | ||
| + | with open(' | ||
| + | template_html = file.read() | ||
| + | |||
| + | # Insérer toutes les variables dans le body | ||
| + | contenu_html = template_html.format( | ||
| + | client=client, | ||
| + | description=description, | ||
| + | start_date=start_date, | ||
| + | start_time=start_time, | ||
| + | equipement=equipement, | ||
| + | incident_ref=incident_ref, | ||
| + | impact=impact, | ||
| + | statut=statut, | ||
| + | perimetre = perimetre | ||
| ) | ) | ||
| Ligne 171: | Ligne 247: | ||
| mail.HTMLBody = contenu_html | mail.HTMLBody = contenu_html | ||
| mail.Display() | mail.Display() | ||
| + | |||
| + | def client1_fin_incident_notif(): | ||
| + | # Demande des infos à l' | ||
| + | destinatairessecondaires = input(" | ||
| + | perimetre = input(" | ||
| + | description = input(" | ||
| + | start_date = input(" | ||
| + | start_time = input(" | ||
| + | equipement = input(" | ||
| + | incident_ref = input(" | ||
| + | impact = input(" | ||
| + | statut = input(" | ||
| + | client = " | ||
| + | |||
| + | # Demande si on doit faire une notif mattermost ou non | ||
| + | notif_equipe = input(" | ||
| + | |||
| + | if notif_equipe == ' | ||
| + | notif_fin_mattermost_client1(webhook_url, | ||
| + | |||
| + | # Concatenne les variables | ||
| + | sujetmail = " | ||
| + | destinataires = " | ||
| + | destinatairescopie = " | ||
| + | |||
| + | # Charger le template HTML depuis un fichier externe | ||
| + | with open(' | ||
| + | template_html = file.read() | ||
| + | |||
| + | # Insérer toutes les variables dans le body | ||
| + | contenu_html = template_html.format( | ||
| + | client=client, | ||
| + | description=description, | ||
| + | start_date=start_date, | ||
| + | start_time=start_time, | ||
| + | equipement=equipement, | ||
| + | incident_ref=incident_ref, | ||
| + | impact=impact, | ||
| + | statut=statut, | ||
| + | perimetre = perimetre | ||
| + | ) | ||
| + | |||
| + | # Créer et afficher le mail Outlook | ||
| + | outlook = win32.Dispatch(' | ||
| + | mail = outlook.CreateItem(0) | ||
| + | mail.Subject = sujetmail | ||
| + | mail.To = destinataires | ||
| + | mail.CC = destinatairescopie | ||
| + | mail.HTMLBody = contenu_html | ||
| + | mail.Display() | ||
| + | |||
| + | #fonction d' | ||
| + | def notif_mattermost(webhook_url, | ||
| + | |||
| + | message_mattermost = "🚨 Incident critique : [" + client + "] " + incident_ref + " - " + description + " - " + impact + " - " + statut + " 🚨" | ||
| + | |||
| + | # Contenu du message | ||
| + | message = { | ||
| + | " | ||
| + | } | ||
| + | |||
| + | # Envoyer la requête POST | ||
| + | response = requests.post( | ||
| + | webhook_url, | ||
| + | data=json.dumps(message), | ||
| + | headers={' | ||
| + | ) | ||
| + | |||
| + | # Vérifier la réponse | ||
| + | if response.status_code == 200: | ||
| + | print(" | ||
| + | else: | ||
| + | print(f" | ||
| + | |||
| + | #fonction d' | ||
| + | def notif_fin_mattermost(webhook_url, | ||
| + | # URL du webhook Mattermost | ||
| + | |||
| + | message_mattermost = "✅ Fin d' | ||
| + | |||
| + | # Contenu du message | ||
| + | message = { | ||
| + | " | ||
| + | } | ||
| + | |||
| + | # Envoyer la requête POST | ||
| + | response = requests.post( | ||
| + | webhook_url, | ||
| + | data=json.dumps(message), | ||
| + | headers={' | ||
| + | ) | ||
| + | |||
| + | # Vérifier la réponse | ||
| + | if response.status_code == 200: | ||
| + | print(" | ||
| + | else: | ||
| + | print(f" | ||
| + | |||
| + | #fonction d' | ||
| + | def notif_mattermost_client1(webhook_url, | ||
| + | |||
| + | message_mattermost = "🚨 Incident critique : [" + client + "] " + incident_ref + " - " + perimetre + " - " + description + " - " + impact + " - " + statut + " 🚨" | ||
| + | |||
| + | # Contenu du message | ||
| + | message = { | ||
| + | " | ||
| + | } | ||
| + | |||
| + | # Envoyer la requête POST | ||
| + | response = requests.post( | ||
| + | webhook_url, | ||
| + | data=json.dumps(message), | ||
| + | headers={' | ||
| + | ) | ||
| + | |||
| + | # Vérifier la réponse | ||
| + | if response.status_code == 200: | ||
| + | print(" | ||
| + | else: | ||
| + | print(f" | ||
| + | |||
| + | #fonction d' | ||
| + | def notif_fin_mattermost_client1(webhook_url, | ||
| + | # URL du webhook Mattermost | ||
| + | |||
| + | message_mattermost = "✅ Fin d' | ||
| + | |||
| + | # Contenu du message | ||
| + | message = { | ||
| + | " | ||
| + | } | ||
| + | |||
| + | # Envoyer la requête POST | ||
| + | response = requests.post( | ||
| + | webhook_url, | ||
| + | data=json.dumps(message), | ||
| + | headers={' | ||
| + | ) | ||
| + | |||
| + | # Vérifier la réponse | ||
| + | if response.status_code == 200: | ||
| + | print(" | ||
| + | else: | ||
| + | print(f" | ||
| # appel du menu | # appel du menu | ||
| menu() | menu() | ||
| + | |||
| + | |||
| </ | </ | ||