1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
Dim fso,of1
Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set rs2 = CreateObject("ADODB.Recordset")
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
conn.Open "PROVIDER=SQLOLEDB;DATA SOURCE=1***;UID=***;PWD=a***t;DATABASE=ic**s"
'msgbox "OK"
datefin = Date
datedebut = DateAdd("d",-7,datefin)
chemin= Replace(WScript.ScriptFullName, WScript.ScriptName, "")
Public Sub SendMail(Expediteur,Destinataire,Sujet,Message,Fichier,Smtp,Port)
Set Mail = CreateObject("CDO.Message")
With Mail
.From=Expediteur
.To=Destinataire
.Subject=Sujet
.CreateMHTMLBody "file://" & Message
.AddAttachment Fichier
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Smtp
.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Port
.Configuration.Fields.Update
.Send
End With
End Sub
chemin= Replace(WScript.ScriptFullName, WScript.ScriptName, "")
dim ori
Set fa = fso.OpenTextFile(chemin & "message_html\message.html", ForReading)
ori = fa.ReadAll
fa.Close
Message = chemin & "message_html\message.html"
If (fso.FileExists(chemin &"liste-client.txt" )) Then
fso.DeleteFile chemin &"liste-client.txt",True
End If
'MsgBox chemin
With rs
rs.Open "SELECT emp, puntoventa FROM tgptoventa", conn
Do While Not rs.EOF
Set f = fso.OpenTextFile(chemin & "\sql-invite-facebook.sql", ForReading)
une_variable = Replace(f.ReadAll, "datedebut", datedebut)
une_variable = Replace(une_variable , "datefin", datefin)
une_variable = Replace(une_variable, "idsociete", rs("emp"))
une_variable = Replace(une_variable, "pointdevente", rs("puntoventa"))
f.Close
'msgbox (une_variable)
With rs2
rs2.Open une_variable, conn
Do While Not rs2.EOF
'msgbox (rs2("nomclient"))
modif = replace(ori, "nomclient",rs2("nomclient"))
modif = replace(modif, "voiture",rs2("modele"))
modif = replace(modif, "societe",rs2("societe"))
Set temp = fso.OpenTextFile(chemin & "message_html\message-temp.html", ForWriting,true)
temp.write(modif)
temp.Close
Message = chemin & "message_html\message-temp.html"
SendMail "No_reply@a***m",rs2("Email"),"Suivez le g*** sur F*ok",Message, "","smtp.fr.oleane.com","25"
fso.DeleteFile chemin & "message_html\message-temp.html",True
Set tf = fso.OpenTextFile(chemin & "liste-client.txt", ForAppending,true)
tf.write(rs2("nomclient")&";"&rs2("modele")&";"&rs2("societe")& vbCrLf )
tf.Close
rs2.MoveNext
Loop
rs2.Close
End With
rs.MoveNext
Loop
rs.Close
End With
Set nb = fso.OpenTextFile(chemin & "liste-client.txt", ForReading)
ts = nb.ReadAll '-- Lit la totalité du fichier
'Wscript.echo (nb.Line-1) '-- Récupère le nombre de lignes
nb.close
SendMail "No_reply@amplitude-auto.com","f**@a***de-auto.com","Le ******",chemin & "message_html\message-direction.html",chemin & "liste-client.txt","smtp.fr.oleane.com","25"
If (fso.FileExists(chemin &"liste-client.txt" )) Then
msgbox ("ok")
fso.DeleteFile chemin &"liste-client.txt",True
End If
Set rs=nothing |
Partager