une erreur de ce type
est typique d'un manque d'autorisation de gmail
La configuration à adopter est bien
' Il faut activer la référence Microsoft CDO
Sub SendEmailUsingGmail()
On Error GoTo Err
Dim NewMail As Object
Dim mailConfig As Object
Dim fields As Variant
Dim msConfigURL As String
Set NewMail = CreateObject("CDO.Message")
Set mailConfig = CreateObject("CDO.Configuration")
' load all default configurations
mailConfig.Load -1
Set fields = mailConfig.fields
With NewMail
.Subject = "Test Mail"
.From = "moi@gmail.com"
.To = "xxxxxxxxx@yyyyyyy.zz" ' mettre ; entre chaque adresse mail
.CC = ""
.BCC = ""
.HTMLBody = "Write your complete HTML Page"
End With
msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
With fields
'Enable SSL Authentication
.Item(msConfigURL & "/smtpusessl") = True
'Make SMTP authentication Enabled=true (1)
.Item(msConfigURL & "/smtpauthenticate") = 1
'Set the SMTP server and port Details
.Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
.Item(msConfigURL & "/smtpserverport") = 465
.Item(msConfigURL & "/sendusing") = 2
'Set your credentials of your Gmail Account
.Item(msConfigURL & "/sendusername") = "moi@gmail.com"
.Item(msConfigURL & "/sendpassword") = "mypwd"
'Update the configuration fields
.Update
End With
NewMail.Configuration = mailConfig
NewMail.Send
MsgBox ("OK, c'est parti !")
Exit_Err:
Set NewMail = Nothing
Set mailConfig = Nothing
End
Err:
Select Case Err.Number
Case -2147220973 'Could be because of Internet Connection
MsgBox " Could be no Internet Connection !! -- " & Err.Description
Case -2147220975 'Incorrect credentials User ID or password
MsgBox "Incorrect Credentials !! -- " & Err.Description
Case Else 'Rest other errors
MsgBox "Error occured while sending the email !! -- " & Err.Description
End Select
Resume Exit_Err
End Sub
Il faut maintenant aller voir dans ta boite gmail et répondre
Tentative de connexion bloquée
puis
Consulter activité
et répondre
C'était moi !
puis
Vous pouvez désactiver l'accès pour ces applications (recommandé) ou l'activer si vous voulez les utiliser malgré les risques encourus.
et enfin
en savoir plus ...
Oui c'est un peu blindé aujourd'hui
Il faut aller jusqu'au bout, jusque "en savoir plus"