Sending CDO Email Using Gmail

Discussion in 'Site Programming, Development and Design' started by Jonathan Kinsman, Mar 16, 2018.

  1. I'm attempting to send email using CDO and Gmail in ASP Classic and get the following error:

    error '80040211'

    Here is my code. [gmail address], [gmail password], and [to address] have actual values, but I didn't want to post them here.

    <%
    Dim objMessage
    Dim objConfig
    Dim Flds

    set objMessage = createobject("cdo.message")
    set objConfig = createobject("cdo.configuration")
    Set Flds = objConfig.Fields

    Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

    ' Passing SMTP authentication
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="[gmail address]"
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="[gmail password]"
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 'basic (clear-text) authentication
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
    Flds.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30

    Flds.update
    Set objMessage.Configuration = objConfig
    objMessage.To = "[to address]"
    objMessage.From = "[gmail address]"
    objMessage.Subject = "Test"
    objMessage.fields.update
    objMessage.HTMLBody = "This is a test sent from CDO using smtp authentication."
    objMessage.Send

    %>

    Any ideas? Thanks!
     
  2. Elshadriel

    Elshadriel Winhost Staff

  3. Thanks! As a follow-up, I got the above code working by "enabling less secure apps" on G Suite.
     
    ComputerMan and Elshadriel like this.
  4. Elshadriel

    Elshadriel Winhost Staff

    Thanks for that follow-up, Jonathan. I'm sure it will help others in the future.
     

Share This Page