Sending Email through Gmail using VB 6.0
Posted by codingsense on July 17, 2009
Hi,
Here is a sample code that is used to send emails from any SMPT server using CDO in Visual Basic 6.0.
Here first i have added a reference to the project by navigating to Project -> references and adding Microsoft CDO for windows 2000 Library.
Sub SendEmail()
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
' send one copy with Google SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "smtp.gmail.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = Username@gmail.com
Flds.Item(schema & "sendpassword") = password
Flds.Item(schema & "smtpusessl") = 1
Flds.Update
With iMsg
.To = To
.From = username@gmail.com
.Subject = "Mail from gmail"
.HTMLBody = "Test message using CDO in vb6 from Gmail smtp"
Set .Configuration = iConf
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Sub
If you need to send mail from .Net here is the procedure.
Thanks,
Naveen Prabhu
Filip said
Hi
Thanks for the code – worked perfectly
Niraj Sinha said
Hi,
while sending it is giving an error message: run-time error ‘-2147220973(80040213)’:The transport failed to connect to the server.
codingsense said
Hi,
Check if you have given proper email id and password.
Thanks,
Naveen Prabhu
jayant said
can we send a mail with out using the authentication.
i mean to say with out user ID and Password
codingsense said
Hi,
No you cannot access gmail SMTP server without authentication. Without logging inside the server you cannot send the mail.
Thanks,
Naveen
Kyle said
thank you so much, you have made a big difference, I have seen alot of code out there, but non of them worked like yours.
keep doing the great job!
Thanks. Kyle
codingsense said
Hi Kyle,
Thanks for the comments. Your support will inspire me to help the community more.
Thanks,
Naveen Prabhu