[vbs] gmail sender

Description

En Réponse à des questions fréquament posés dans les forums et dans les commentaries voila je poste ce petit script qui va peut-être répondre presque à tous vos questions comme par exemple: comment ajouter un champ CC ou bien un champ BBC avec ajout d'une pièce-jointe et l'envoyer automatiquement.
Description de ce VBscript:
Envoyer un message électronique HTML avec fichier joint via les serveurs Gmail en utilisant l'authentification SMTP et SSL.
C'est comme tout autre courrier, mais exige que vous définissez le port SMTP à 465 et le CDO utilise le SSL

Source / Exemple :


'Envoyer un message électronique HTML avec fichier joint via les serveurs Gmail en utilisant l'authentification SMTP et SSL. 
'C'est comme tout autre courrier, mais exige que vous définissez le port SMTP à 465 le CDO utilise le SSL
'By Hackoo © 2011
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
sFilePath="C:\SSLGmail.rar" 'Path of the Attached File
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "Example CDO Message" 
objMessage.From = """Me"" <Mymail@gmail.com>" 'change this to yours
objMessage.To = "dest@yahoo.fr" 'change this To
objMessage.CC = "dest2@yahoo.fr" 'change this CC means : Carbon Copy
objMessage.BCC = "dest3@gmail.com" 'change this BCC means : Blink Carbon Copy
sBody = "<center><font size=4 FACE=Tahoma Color=red>This is some sample message in HTML.<br> It was sent using SMTP authentication and SSL."
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") = "smtp.gmail.com" 'SMTP SERVER of GMAIL must be inchanged

'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") = "YourLoginGmail@gmail.com" 'change this to yours

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "YourPasswordGmail" 'change this to yours

'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

Conclusion :


Vos Remarques et vos commentaires sont les Bienvenus !

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.