locked
Error while sending mails using CDO.Message object RRS feed

  • Question

  • Hi All,

    I am trying to send mails from my excel using VBA and CDO.Message and CDO.Configuration Object

    See the below code
    ------------------------------
    Function SendMailTo(sTo, sSubject, sBody)
    Dim oMsg As Object
    Dim oConf As Object
    Dim Flds As Object
    Dim strSch As String
    Const cdoBasic = 1
    Set oMsg = CreateObject("CDO.Message")
    Set oConf = CreateObject("CDO.Configuration")
    oConf.Load -1 ' CDO Source Defaults
    Set Flds = oConf.Fields
    strSch = "http://schemas.microsoft.com/cdo/configuration/"

    With Flds
    .Item(strSch & "sendusing") = 2
    .Item(strSch & "smtpauthenticate") = cdoBasic
    .Item(strSch & "smtpserver") = "smtp.gmail.com"
    .Item(strSch & "sendusername") = "srinivas.2447.p@gmail.com"
    .Item(strSch & "sendpassword") = "****" 'my password is given
    .Item(strSch & "smtpserverport") = 465
    .Item(strSch & "smtpusessl") = True
    .Update
    End With

    With oMsg
    Set .Configuration = oConf
    .To = sTo
    .CC = ""
    .Bcc = ""
    .From = """Srinivas P"" <srinivas.2447.p@gmail.com>"
    .Subject = sSubject
    .TextBody = sBody
    .Send
    End With


    Set oMsg = Nothing
    Set oConf = Nothing

    End Function
    ------------------------------------------------------------------------------------------------------------

    now when i call this function it throws an error : "Transport failed to connect to the server" i dont want to use any outlook kind of a thing.

    Any solutions would be appreciated.

    Thanks in advance,
    Srinivas P.

     

    Tuesday, August 7, 2007 9:40 AM