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
|
Sub EnvoiMailCDO()
Dim mMessage As Object
Dim mConfig As Object
Dim mChps
Set mConfig = CreateObject("CDO.Configuration")
mConfig.Load -1
Set mChps = mConfig.fields
With mChps
.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Adapter suivant votre serveur de mail. (exemple pour Gmail.)
.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
'En principe, 25 fonctionne avec tout les serveurs.
.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
'Vous pouvez essayer sans ces trois lignes
'Mais si votre serveur demande une authentification,
.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "L'adresse email complète de Gmail"
.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "le mot de passe Gmail"
'Si votre serveur demande une connexion sûre (SSL)
.item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = "true"
.item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With
Set mMessage = CreateObject("CDO.Message")
With mMessage
Set .Configuration = mConfig
.from = "monemail"
.To = "l'email à joindre"
.Subject = "Le sujet du mail"
.TextBody = "Ce mail vous est envoyer pour tester"
'Pour ajouter une pièce jointe, un fichier, classeur, image etc.
'.AddAttachment 'Chemin et nom complet du fichier à joindre
.fields.Update
.send
End With
Set mMessage = Nothing
'Libère les ressources
Set mConfig = Nothing
Set mChps = Nothing
End Sub |
Partager