# -*- coding: utf8 -*- from pyramid.response import Response from pyramid.view import ( view_config, ) @view_config(route_name='batch_nuit') def batch_nuit(request): """ Traitement de nuit lancé chaque nuit à heure fixe par cron Par sécurité, ce view ne peut être appelé qu'avec un paramètre secret 'JonSn0w' """ # import pdb;pdb.set_trace() # contrôle : paramètre correct ? non, terminer par = request.matchdict['param'] if par != 'JonSn0w': return Response('Erreur : paramètre incorrect') return Response('Batch nuit terminé OK') def notifier_rappels(request): szSQL = "insert t_log_nuit (proc,msg) values ('RAPPELS','- Début ENVOI emails');" ExecQuery(ctDSN_AEM, szSQL) szSQL = "SELECT r.*, e.c_qualite, e.c_nom, e.c_adr, e.c_adr2, e.c_ville, e.c_email, s.tel, s.nom as nom_societe FROM email_rappels r " & _ "INNER JOIN dem_devis e ON r.societe = e.societe AND r.nochantier = e.no_id " & _ "INNER JOIN p_societe s ON r.societe = s.societe " & _ "WHERE ISNULL(envoye_le) ORDER BY no_id;" GetRecordset(ctDSN_AEM, szSQL, rsRappel) Do While Not rsRappel.EOF nbLus += 1 If rsRappel.Fields("c_email").Value.ToString.Length = 0 Then nbEmailVide += 1 szSQL = "insert t_log_nuit (proc,msg) values ('RAPPELS', '--> email vide : " & rsRappel.Fields("societe").Value & "-" & nq(rsRappel.Fields("nochantier").Value) & _ " - " & rsRappel.Fields("c_qualite").Value & " " & nq(rsRappel.Fields("c_nom").Value) & "');" ExecQuery(ctDSN_AEM, szSQL) Else ' RDV ayant une heure date_heure = Format(rsRappel.Fields("rdv_date").Value, "dd/MM/yyyy à HH:mm") szBody = "
Bonjour " & nv(rsRappel.Fields("c_qualite").Value) & " " & rsRappel.Fields("c_nom").Value & ",
" & _ "L’entreprise " & rsRappel.Fields("nom_societe").Value & " vous rappelle votre prochain rendez-vous, pris d'un commun accord,
" & _ "le " & date_heure & "
" & _
rsRappel.Fields("c_adr").Value & "
" &
IIf(rsRappel.Fields("c_adr2").Value.ToString.Length > 0, rsRappel.Fields("c_adr2").Value & "
", "") & _
rsRappel.Fields("c_ville").Value & "
" & "
" & _ "
En cas d'empêchement, veuillez nous contacter au " & rsRappel.Fields("tel").Value & "." & _ "
Veuillez agréer nos sincères salutations.
" & _ "L'entreprise " & rsRappel.Fields("nom_societe").Value & "
" SendNotification(ctDSN_AEM, "RAPPEL : rendez-vous le " & date_heure, szBody, rsRappel.Fields("c_email").Value, rsRappel.Fields("societe").Value) nbEnvoyes += 1 End If ' marquer le rdv comme envoyé ou traité szSQL = "UPDATE email_rappels SET envoye_le = NOW() WHERE no_id = " & rsRappel.Fields("no_id").Value ExecQuery(ctDSN_AEM, szSQL) ' Get the next record rsRappel.MoveNext() Loop ' Close the recordset AND connection. rsRappel.Close() szSQL = "insert t_log_nuit (proc,msg) values ('RAPPELS','- Fin ENVOI emails : " & nbLus & " rdv lus, " & nbEnvoyes & " rappels envoyés, soit " & Math.Round(nbEnvoyes * 100 / nbLus, 0).ToString & " % envoyés.');" ExecQuery(ctDSN_AEM, szSQL) return def email_rappels: ' Lire la societe szSQL = "SELECT * FROM p_societe WHERE societe='" & societe & "';" GetRecordset(ctDSN_AEM, szSQL, rs) If rs.RecordCount > 0 Then szFrom = rs.Fields("email_from").Value Else szFrom = "peinture@entreprise-dumas.com" End If rs.Close() rs = Nothing ' Set the SMTP server Dim Smtp_Server As New SmtpClient(My.Settings.SmtpHost, My.Settings.SmtpPort) If My.Settings.SmtpSSL = "True" Then ' envoyer la notification avec le compte de l'agence Smtp_Server.Credentials = New Net.NetworkCredential(My.Settings.SmtpUsername, My.Settings.SmtpPassword) End If Smtp_Server.EnableSsl = My.Settings.SmtpSSL If My.Settings.SmtpUsername = "cao.thien-phuoc@orange.fr" Then szFrom = My.Settings.SmtpUsername szEmail = "ctphuoc@gmail.com" szCCI = "ctphuoc@gmail.com" End If ' create the mail message Dim mail As New MailMessage() mail.From = New MailAddress(szFrom, "Entreprise DUMAS") 'set the content mail.Subject = szSubjet mail.IsBodyHtml = True mail.Body = szBody mail.To.Add(szEmail) Try Smtp_Server.Send(mail) Catch error_t As Exception MsgBox(error_t.ToString, MsgBoxStyle.Critical) Exit Sub End Try