Building a Commercial e-Statement Application in VB 6 – Send Mail Using Gmail SMTP Server
Am glade you find time to visit our website. If this is your first time on this website and you want to learn how to develop your own e-Statement application from scratch go to the beginning where it all started E-statement Basics
As we go on with the development of this e-Statement application, at some point we will need to start testing sending emails from the application. And for this to happen we require to have SMTP Server which will send the mails. So in today`s post we will take a look at how to send mail using Gmail SMTP server in vb6.
In Summary, we are going to do the following in this article
- Set access for less secure apps
- Send Mail Using Gmail SMTP Server
- Test your application
Set access for less secure apps in GMail
This part is crucial if we want to use Gmail SMTP Server to send mail via vb6. Login to your Gmail account. Click on “Account”
and go to the “Signing In” set “Access for less secure apps” to Allowed
The above step is a must because before we send mail through Google`s SMTP Server we need to authenticate and the authentication will be blocked if we have not “Allowed” access for less secure apps.
Send Mail Using Gmail SMTP Server
Once we have “Allowed” access for less secure apps in Gmail we are now ready to send a test mail using Gmail SMTP Server. This is important for the e-Statement application because going forward we are going to use these same settings to send our e-Statements.
Open your SmartMail in your Visual Basic IDE and add a Form. Add one Command Button and name it as cmdSendMail. Double click the command button and add the below code. Please change the Username and Password in the code to use your Gmail Email Address and Password.
Just as a reminder , you will need to reference the CDO Library for the code below to work properly.
'eStatement Application Development 'Send Mail Using Google`s SMTP Server 'www.smarttechdiary.com Private Sub cmdSendMail_Click() Dim myMail As CDO.Message Set myMail = New CDO.Message myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email@example.com" 'Your Gmail Account myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "YourGmailPassword" 'Your Password myMail.Configuration.Fields.Update With myMail .Subject = "Your Monthly e-Statement - SMART TECH DIARY DOT COM" .From = "firstname.lastname@example.org" .To = "email@example.com" .CC = "" .BCC = "" .TextBody = "The Smart Tech Diary" End With On Error Resume Next myMail.Send MsgBox ("Sent") Set myMail = Nothing End Sub
Run your project and test your SMTP Sever settings
I received the test mail as below which means the SMTP Server settings are working correctly on my side
If you have any questions,kindly contact me I will try my best to help you out. Have a nice week. If you like these posts kindly share with your friends by clicking the buttons below.