Bonjour,
Je viens de débuter en VBS et je voulais savoir comment envoyer un mail. J'ai trouvé mais quand je mets le contenu d'un fichier texte dans une variable qui est le corps du texte et que j'envoie j'ai deux solutions. Premier, le contenu du fichier est court, sans caractère spéciaux et tout, ça marche. Deuxième, avec un contenu plus et plus compliqué, j'obtiens ceci : "яю=".
Voici le code (voir lignes 13 à 17):
Si vous avez la grâce de m'aider je vous en serez très reconnaissant.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 On Error Resume Next Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). Const cdoAnonymous = 0 'Do not authenticate Const cdoBasic = 1 'basic (clear-text) authentication Const cdoNTLM = 2 'NTLM Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Example CDO Message" objMessage.From = """Me"" <>" 'change this to yours objMessage.To = "" 'change this To objMessage.CC = "" 'change this CC means : Carbon Copy objMessage.BCC = "" 'change this BCC means : Blink Carbon Copy Const ForReading = 1, ForWriting = 2, ForAppending = 8 Set fso = CreateObject("Scripting.FileSystemObject" ) Set f = fso.OpenTextFile("1.txt", ForReading) sBody = f.ReadAll f.Close 'Extraction du contenu' objMessage.HTMLBody = sBody & _ "<center><font size=4 FACE=Tahoma Color=red>" & _ messageHTML & _ "<br><br><img src=http://photomaniak.com/upload/out.php/i1102064_IDNlogo.gif>" objMessage.AddAttachment sFilePath '==This section provides the configuration information for the remote SMTP server. objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Name or IP of Remote SMTP Server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "" 'Type of authentication, NONE, Basic (Base64 encoded), NTLM objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic 'Your UserID on the SMTP server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "" 'Your password on the SMTP server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "" 'Server port (typically 25 and 465 in SSL mode for Gmail) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'don't change this 'Use SSL for the connection (False or True) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True 'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 objMessage.Configuration.Fields.Update '==End remote SMTP server configuration section== objMessage.Send If Err.Number <>0 Then MsgBox Err.Description,16,"Erreur" msgbox "le mail n'a pas pu être envoyé !",16,"Information" Else msgbox "Le mail a été bien envoyé !",64,"Information" End If On Error GoTo 0
J'oubliais, voici le type de contenu complexe :
==================================================
Des choses écrites
Beaucoup de choses écrites
==================================================
Merci d'avance
Partager