Home  Fees/Services  Access 2010 Template  Access Tutorial  Access Download  Articles  Search  Forums  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 #1
Send Gmail Email #2
Inactivity Logout Code
Outlook Email
Read Email Access
Email Attachment
Send Outlook Email
Running Sum
Denormalize Records
Stock Quotes
Find Database Path
Detail-Master Update
Data Field Validation
Field Value New-Old
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 To Gmail Using Access VBA

Send Email from Access to Gmail:  We have come up with another more flexible method for sending email using Google Gmail rather than MS Outlook or Exchange Server.

Microsoft Access is a fully capable database and it's primary limitations is the number of concurrent users it will support. Generally, we recommend a limit of 10 to 15 users.

We create databases large and small. Some of our databases help run entire small businesses. We also handle unique businesses such as flyrod manufacturing, cheese making, marina management, and cable tv inventory.

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

View our 2nd CDO Email example that shows the settings required on the Gmail side: Send Gmail Email From Access

Blue Claw Database Design Downloadable Tutorial:
Running Sum Query Method  

A Blue Claw Software Design Template:

Airline Reservations Database Template

A Blue Claw Database Design Article:

Learn How To Select A Consultant

Microsoft Office:
MS Access 2000 Through 2016 and Office 365 & Sharepoint

Contact Information

Copyright 2000-2017 Blue Claw Database Design

Microsoft Access 2007, 2010, 2013 & 2016