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

Access CDO Email VBA
Send Email to Gmail

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

Send Gmail Email From Access VBA


The sample database provided gives an example of sending an email through Access using Gmail.  In order for this to work, you must have a Gmail account, and know your user id and password. Also, in your Gmail settings, you will want to turn on less secure apps to avoid transport errors: (https://www.google.com/settings/security/lesssecureapps)

Gmail From Access Example Code

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.

Did you know you don't need to move to SQL/Server to run and manage your Access database on the net. There are many alternative solutions. Among them are Amazon's AWS cloud services and various hosting services in nearly every state.

After you set up your Company Emails and Passwords, the database utilizes your Gmail address and password that is selected on the Control Panel tab, to send your email. This is helpful when you have more than one person that needs to send emails. It also uses your customers’ email address that is set up in Contacts. If you have the need to send emails to different people for different reasons (i.e.. Invoices go to janedoe@company.com and status updates go to suesmith@company.com), the sample database (below) allows for separate email addresses, and also allows for multiple email addresses. The email function will send to everyone in the field. Separate the addresses by semi-colons or commas.


Here’s the code:

  Dim msg As Object


        Set msg = CreateObject("CDO.Message")


msg.From = Forms![mainentry]![UserEmail] ‘This is the user email chosen on the Control Panel tab. Must be a GMAIL account.

        msg.to = [Forms]![mainentry]![invoiceemail1]’This is the Contact’s email address(es) where invoices get sent to



        msg.Subject = "Your Invoice is Attached"

        msg.textbody = "Thank you!"

        msg.CC = ""

        msg.BCC = ""

        msg.ReplyTo = Forms![mainentry]![UserEmail] ‘Again, the user email from the Control Panel


        msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

        msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

        msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

        msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = Forms![mainentry]![UserEmail] ‘Again, the user email from the Control Panel

        msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Forms![mainentry]![password]’The user password from the Control Panel

        msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

        msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1



msg.HTMLBody = "<font size='2' face='Verdana, Arial, Helvetica, sans-serif'>"

'msg.HTMLBody = "Thank you!"

msg.HTMLBody = msg.HTMLBody & "<font face=""arial"" size=""2"" color=""blue"">"

‘Following is the address block that gets inserted at the bottom of the email

msg.HTMLBody = msg.HTMLBody & "<font face=""arial"" size=""2"" color=""black""Test Company Name</font><BR>"

msg.HTMLBody = msg.HTMLBody & "<font face=""arial"" size=""2"" color=""black"">418 Anywhere Rd.</font><BR>"

msg.HTMLBody = msg.HTMLBody & "<font face=""arial"" size=""2"" color=""black"">Ellisville, MS 39437</font><BR>"

msg.HTMLBody = msg.HTMLBody & "<font face=""arial"" size=""2"" color=""black"">(555) 555-2675 office</font><BR>"

msg.HTMLBody = msg.HTMLBody & "<font face=""arial"" size=""2"" color=""black"">(555) 555-9532 fax</font><BR>"

msg.HTMLBody = msg.HTMLBody & Forms![mainentry]![UserEmail]’Inserts the users’ email into the address block

msg.HTMLBody = msg.HTMLBody & "<font face=""Arial"" size=""2"" color=""green""><u>" & SW & "</u></font><BR>"

msg.HTMLBody = msg.HTMLBody & "<font face=""Arial"" size=""2"" color=""blue"">"


        MsgBox "Invoice Sent"

‘You can comment out this last line if you don’t want to be notified every time your email is sent.

         Exit Sub



    MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _

           VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"

End Sub

For your programming enjoyment we have included a free Access Database Gmail CDO example download for you to practice with.  Feel free to use the code in your databases.

Blue Claw Database Design Downloadable Tutorial:
DoCmd.OpenForm & OpenArgs VBA Example.  

A Blue Claw Software Design Template:

Real Estate Marketing Campaign System

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-2018 Blue Claw Database Design

Microsoft Access 2007, 2010, 2013 & 2016