Send Gmail Email From Access VBA
Home  Fees/Services  Access 2010 Template  Access Tutorial  Access Download  Articles  Search  Forums  Blockchain Tech  Contact  Privacy  Links

<%if len(crumb2)>2 then response.write crumb2 else response.write ">


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: (

Gmail From Access Example Code

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 and status updates go to, 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. = [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("") = ""

        msg.Configuration.Fields("") = 465

        msg.Configuration.Fields("") = 2

        msg.Configuration.Fields.Item("") = Forms![mainentry]![UserEmail] ‘Again, the user email from the Control Panel

        msg.Configuration.Fields.Item("") = Forms![mainentry]![password]’The user password from the Control Panel

        msg.Configuration.Fields.Item("") = True

        msg.Configuration.Fields.Item("") = 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.


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

Contact Information

Blue Claw Database Design

Microsoft Access 2007, 2010, 2013 & 2016