Browse Source

Maj mail_rappel: mail au format html, template deplace vers fichier
mail.html

olivier.massot 8 years ago
parent
commit
d92d1df50c
5 changed files with 52 additions and 26 deletions
  1. 2 2
      core/logging.yaml
  2. 6 1
      core/mail.py
  3. 1 1
      core/webservice.py
  4. 30 0
      mail.html
  5. 13 22
      mails_rappel_ctrl.py

+ 2 - 2
core/logging.yaml

@@ -47,9 +47,9 @@ loggers:
         level: INFO
         handlers: [console]
         propagate: no
-    ctrl_mailing:
+    mails_rappel_ctrl:
         level: INFO
-        handlers: [console, file, mail]
+        handlers: [console, file,mail]
         propagate: no       
           
 root:

+ 6 - 1
core/mail.py

@@ -6,9 +6,11 @@ usage:
     m.send()
 
 '''
+from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
 import smtplib
 
+
 class Mail():
     HOST = "smtp.bas-rhin.fr"
 
@@ -22,11 +24,14 @@ class Mail():
     def send(self):
         port = self.mailport if self.mailport else smtplib.SMTP_PORT
 
-        msg = MIMEText(self.msg.encode('utf-8'), _charset='utf-8')
+        msg = MIMEMultipart('alternative')
+#         msg = MIMEText(self.msg.encode('utf-8'), _charset='utf-8')
         msg['Subject'] = self.subject
         msg['From'] = self.fromaddr
         msg['To'] = ",".join(self.toaddrs)
 
+        msg.attach(MIMEText(self.msg, 'html', _charset='utf-8'))
+
         smtp = smtplib.SMTP(self.HOST, port)
         smtp.sendmail(self.fromaddr, self.toaddrs, msg.as_string())
         smtp.quit()

+ 1 - 1
core/webservice.py

@@ -10,7 +10,7 @@ from lxml import etree  # @UnresolvedImport
 
 logger = logging.getLogger("webservice")
 
-PDE_WS_URL = r"\\asp-01\inetpub\DotNet4Root\webservices\CG67.AstreGF.WebServices"
+PDE_WS_URL = r"http://webservices.bas-rhin.fr/CG67.AstreGF.WebServices/public/WsPDE.asmx"
 # PDE_WS_URL = 'http://localhost:2890/public/WsPDE.asmx'
 
 class GfWebservice():

+ 30 - 0
mail.html

@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+
+<html lang="fr" xmlns="http://www.w3.org/1999/xhtml">
+    <head>
+        <meta charset="utf-8" />
+        <title>Parc Départemental d'Erstein - Rappel</title>
+    </head>
+    
+    <body>
+        <div style="background-color:#f2f2f2;text-align:center;">
+            <i>** Ceci est un mail automatique, veuillez ne pas répondre. **</i>
+        </div>
+
+        <h1 style="font-size: 150%;color:#325d81;">Rappel Chantier {chantier_id}</h1>
+	
+		<p>Bonjour,</p>
+
+        <p style="display: flex;justify-content: flex-start;margin:30px 0 5px 12px;">
+			> le chantier numéro {chantier_id} est en attente d'une intervention depuis le {date_status:%d-%m-%Y}.
+        </p>
+
+        <p style="margin:5px 0 30px 12px;">Pour plus d'information: <a href="mailto:{contact}">{contact}</a></p>
+
+		<p>
+			Merci,<br/>
+			Le Parc Départemental d'Erstein
+		</p>
+
+    </body>
+</html>

+ 13 - 22
ctrl_mailing.py → mails_rappel_ctrl.py

@@ -13,41 +13,30 @@ from core import logconf
 from core.mail import Mail
 from core.pde import ControlesDb
 
-logger = logging.getLogger("ctrl_mailing")
-logconf.start("ctrl_mailing", logging.DEBUG)
+logger = logging.getLogger("mails_rappel_ctrl")
+logconf.start("mails_rappel_ctrl", logging.DEBUG)
 
 # #     CONFIG
+
 # Nombre de jours à partir duquel les mails sont envoyés
 SEUIL_DUREE = 15
 
 # Demarrer la requete de sélection à partir du chantier:
 CHANTIER_DEPART = 175000
 
-# Contact
-CONTACT = "parc.erstein@bas-rhin.fr"
-
 # Adresse mail depuis laquelle les mails sont envoyés
-SENDER = "mail.auto@bas-rhin.fr"
+SENDER = "ne-pas-repondre@bas-rhin.fr"
 
 # Objet des mails automatiques
 SUBJECT = "Mail automatique - Rappel"
 
+# Contact
+CONTACT = "jacky.klein@bas-rhin.fr"
+
 # Contenu des mails automatiques
 #   NB: variables optionelles utilisables dans CONTENT: {chantier_id}, {date_status}, {contact}
-CONTENT = """Bonjour,
--- Ceci est un rappel automatique, veuillez ne pas répondre à cette adresse --
-
-> le chantier numéro {chantier_id} est en attente d'une intervention depuis le {date_status}.
-
-Pour plus d'information: {contact}
-
-Merci,
-Le Parc Départemental d'Erstein
-"""
-
-
-
-
+with open("mail.html", encoding="utf-8") as f:
+    content = f.read()
 
 # #     INITIALISATION
 
@@ -101,9 +90,11 @@ for row in qry:
 
     logger.info("> Chantier %s: envoi d'un mail à %s", chantier_id, mail_to)
     mail = Mail(SENDER,
-                mail_to,
+                [mail_to],
                 SUBJECT,
-                CONTENT.format(chantier_id=chantier_id,
+                content.format(
+                               chantier_id=chantier_id,
                                date_status=since,
                                contact=CONTACT)
                                )
+    mail.send()