Question Locked

error while sending mails using CDO.Message object

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,

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"" "
.Subject = sSubject
.TextBody = sBody
.Send

End With
Set oMsg = Nothing
Set oConf = Nothing

End Function

now when i call this function it says .

"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.

1 reply

This discussion is closed to new replies.