title: Error in sending automatically emails using CDO
body: <p>I've got an Excel Range including mailto email addresses for clients and a path to reach an invoice to enclosed in an email.</p>
  
  <p>My code consists in sending an email (with an invoice) to each mailto address (from my gmail account).</p>
  
  <p>Even if I don't include the attachment, I get an Automation error. Why?</p>
  
  <pre><code>Sub SendMail()
  
  Dim oCdo As Object
  Dim oConf As Object
  Dim Flds As Object
  Dim strHtml As String  'variable contenu du corps de message
  Dim destinataire As String
  Dim attachment As String
  Dim DerLig
  
  ' Définit le contenu du message au format HTML
  strHtml = "&lt;HTML&gt;&lt;HEAD&gt;&lt;BODY&gt;"
  strHtml = strHtml &amp; "&lt;center&gt;&lt;b&gt; Ceci est un message de test au format &lt;i&gt;&lt;Font Color=#ff0000 &gt; HTML. &lt;/Font&gt;&lt;/i&gt;&lt;/b&gt;&lt;/center&gt;"
  strHtml = strHtml &amp; "&lt;/br&gt;Veuillez prendre connaissance de la piece jointe."
  strHtml = strHtml &amp; "&lt;/BODY&gt;&lt;/HEAD&gt;&lt;/HTML&gt;"
  
  DerLig = Range("A" &amp; Rows.Count).End(xlUp).Row
  For n = 1 To DerLig
  n = n + 1
  destinataire = Cells(n, 3).Value
  attachement = Cells(n, 8).Value
  
  Set oCdo = CreateObject("cdo.Message")
  'Set oConf = CreateObject("cdo.configuration")
  'Set Flds = oConf.Fields
  
  With oCdo.configuration.Fields
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 'adresse du serveur smtp
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'tester 25, 465 ou 587
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True  'Utilise une connection SSL (True or False)
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 40
      .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 '0 : pas d'authentification, 1 : authentification basique
      .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MY GMAIL" 'identifiant de messagerie
      .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MY PASSWORD" 'mot de passe de messagerie
      .Update
  End With
  
  With oCdo
      .Subject = "Votre facture"                                            ' objet du message
      .From = "MY GMAIL"                                                   ' adresse de l'expéditeur
      .To = destinataire                                                    ' adresse du destinataire
      .BCC = ""                                                             ' en copie cachée pour conserver trace
      .HtmlBody = strHtml                                                   ' corps du message HTML
      '.AddAttachment (attachement)                                         ' ajout de pièce jointe
      .MDNrequested = True
      .Send
  
  End With
  
  Set oCdo = Nothing
  
  Next n
  
  End Sub
  </code></pre>