02 July 2010

Send mail from your gmail account using VB6 CDO throught SMTP

The following is the function to send email from vb6 application using CDO object.

Public Function SendMail(toMail As String, subject As String, msgBody As String)
     Dim lobj_cdomsg As CDO.Message
     Set lobj_cdomsg = New CDO.Message
     lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = "smtp.gmail.com"
     lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = 465
     lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = True
     lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = 1
     lobj_cdomsg.Configuration.Fields(cdoSendUsername) = "username@gmail.com"
     lobj_cdomsg.Configuration.Fields(cdoSendPassword) = "password"
     lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
     lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = 2
     lobj_cdomsg.Configuration.Fields.Update
     lobj_cdomsg.To = toMail
     lobj_cdomsg.From = "username@gmail.com"
     lobj_cdomsg.subject = subject
     lobj_cdomsg.HTMLBody = msgBody
     lobj_cdomsg.Send
     Set lobj_cdomsg = Nothing
End Function

2 comments:

Feros said...

NOw how to use it? I mean how to call this function?

MALAY MAJITHIA said...

call SendMail("sendmailto@gmail.com", "Subject of the mail", "Hello, " &vbNewLine & "How r u?")