Home  Fees/Services  Access 2010 Template  Access Tutorial  Access Download  Articles  Search  Contact  Privacy  Links

Send Email Access VBA
Gmail Access CDO VB






Visual Basic Tutorials:
Access-Google Earth
Age Calculation
Change To Proper Case
Email via Gmail
Inactivity Logout Code
Outlook Email
Read Email Access
Email Attachment
Send Outlook Email
Running Sum
Concatenate Records
Stock Quotes
CreateQueryDef
Find Database Path
Detail-Master Update
Data Validation
Field Value New-Old
FindFirst
Access Version
Global Variable Parameter
Global Variables
Active Labels
Files List Box
Mail Merge
Quick Sort
Recordset Filters
Reference Form Field
Select Case
Access Transactions


Visual Basic Function Examples


Email via Gmail CDO Method in Access

Send Email from Access through Gmail:  Perhaps you have reviewed our other VBA send Email to Outlook tutorial.  Now we have come up with another more flexible method for sending email using Google Gmail rather than MS Outlook or Exchange Server.

Just like our other email routines, this VBA Email transmission method gives you the capability to automatically generating emails from an Access database.  It is important to note that you can send your email to anyone on the internet and you aren't limited to sending emails just to other Gmail users.

Note that we are using Gmail as an Email server and therefore we can send messages from our desktop out through Gmail to anyone on any Email system.  One of the benefits is that your email message isn't retained on your company's email server.  This method is likely to work with other SMTP email systems (Yahoo, Hotmail, etc.) but we haven't verified those routes.

Our method uses Microsoft's CDO Message routine which requires no additional references in your Access visual basic module.  The CDO message architecture is reference directly on Microsoft's website.

Let's get to it - here is the code in its simplest setup:

Public Function send_email()

Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "mygmail@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
.Update
End With
' build email parts
With cdomsg
.To = "somebody@somedomain.com"
.From = "mygmail@gmail.com"
.Subject = "the email subject"
.TextBody = "the full message body goes here. you may want to create a variable to hold the text"
.Send
End With
    Set cdomsg = Nothing
End Function

In the code above the green text represent comments and the red text variable parts that you need to customize for you data/email accounts.

Also, Gmail has an alternate server port number: 465.  Outlook uses port number 25.

Below is an image of the code so you can more easily remove the line breaks.

Running this code from Access visual basic gives you the ability to add recordset operations in order to grab emails from a table and add looping code to loop through address in order to send out multiple emails.

I believe there are CDO message options for such things as blind CCs, regular CCs, message acknowledgement, and attachments.  You can find these options here: Microsoft CDO Message Components










Blue Claw Database Design Downloadable Tutorial:
TransferText & OutputTo Microsoft Access Download.  








A Blue Claw Database Design Template:

Asbestos Survey Project Database
 










A Blue Claw Database Design Article:

Learn How To Select A Consultant
 


Contact Information

Copyright 2000-2015 Blue Claw Database Design

Microsoft Access 2007, Access 2010, MS Access 2013