title: VBA send email using Gmail: transport failed to connect
body: <p>Running the Excel VBA code below I get the following error:</p>
  
  <blockquote>
    <p>Run-time error -2147220973<br>
    The transport failed to connect to the server</p>
  </blockquote>
  
  <pre><code>Public Function send_email()
  
  Set cdomsg = CreateObject("CDO.message")
  With cdomsg.Configuration.Fields
  .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
  .Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 465
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
  .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "mymail@gmail.com"
  .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypass"
  .Update
  End With
  ' build email parts
  With cdomsg
  .To = "mymail@gmail.com"
  .From = "mymail@gmail.com"
  .Subject = "the email subject"
  .TextBody = "the full message body goes here. you may want to create a variable to hold the text"
  .Send
  End With
      Set cdomsg = Nothing
  End Function
  </code></pre>