Envoyer un mail avec une pièce jointe en VBS

Voici comme envoyer un mail avec un script Visual Basic (VBS) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
dim objOutlk   
dim objMail
dim strMsg

const olMailItem = 0

set objOutlk = createobject("Outlook.Application")
set objMail = objOutlk.createitem(olMailItem)
objMail.To = "toto@titi.fr"
objMail.cc = "titoititi.fr"

objMail.subject = "Titre du mail"
   
    strMsg = "Bonjour," & VbCrLf
    strMsg = strMsg & VbCrLf & "En pièce jointe vous trouverez 1 fichier : " & VbCrLf
    strMsg = strMsg & "- Le fichier en piece jointe contient toto."
    strMsg = strMsg & VbCrLf & "Bien cordialement."

    objMail.attachments.add("C:\piece_jointe.txt")
    objMail.body = strMsg
    objMail.send

set objMail = nothing
set objOutlk = nothing