Home  Fees/Services  Access 2010 Template  Access Tutorial  Access Download  Articles  Search  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
Concatenate Records
Stock Quotes
CreateQueryDef
Find Database Path
Detail-Master Update
Data Field 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


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



Our Access Programmers work with clients all over the world through the Internet. See why we are the: the best Access programming company.

We also have 100's of programming examples from simple to complex. You can jump to our Access tutorials here.


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.Configuration.Fields.Update

 

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

        msg.Send

        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

 

errHandler:

    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:
Union Query (Advanced) Access Tutorial Download  








A Blue Claw Software Design Template:

Construction Project Software
 










A Blue Claw Database Design Article:

Access Form Design Help
 

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