VBA & Macros

Sending Emails from Access with VBA: Outlook and SMTP

Automate email notifications, reports, and alerts directly from Access using VBA. Learn both the Outlook automation approach and direct SMTP sending.

A
Anthony Passeri, MBA
••5 min read
Sending Emails from Access with VBA: Outlook and SMTP

Sending emails directly from Access is one of the most requested automation features. Whether you need to notify a manager when a record is updated, send a report to stakeholders on a schedule, or email customers their invoices, VBA gives you the tools to do it.

Method 1: Outlook Automation (Most Common)

If Outlook is installed on the machine running Access, you can automate it through VBA to send emails. This is the most reliable approach for most business environments.

Add a reference: Tools → References → Microsoft Outlook XX.X Object Library

Sub SendEmailViaOutlook(toAddress As String, subject As String, body As String, _
                         Optional attachmentPath As String = "")
    On Error GoTo ErrorHandler
    
    Dim olApp As Outlook.Application
    Dim olMail As Outlook.MailItem
    
    Set olApp = New Outlook.Application
    Set olMail = olApp.CreateItem(olMailItem)
    
    With olMail
        .To = toAddress
        .Subject = subject
        .Body = body
        
        ' Add attachment if provided
        If attachmentPath <> "" Then
            .Attachments.Add attachmentPath
        End If
        
        .Send  ' Send immediately
        ' Use .Display instead of .Send to show the email for review first
    End With
    
    Set olMail = Nothing
    Set olApp = Nothing
    Exit Sub

ErrorHandler:
    MsgBox "Email error: " & Err.Description
End Sub

Usage:

SendEmailViaOutlook "manager@company.com", _
                    "New Order Received", _
                    "Order #" & Me.OrderID & " has been placed by " & Me.CustomerName

Sending Multiple Recipients

With olMail
    .To = "alice@company.com; bob@company.com"
    .CC = "manager@company.com"
    .BCC = "archive@company.com"
    .Subject = "Monthly Report"
    .HTMLBody = "<h1>Report</h1><p>Please find the report attached.</p>"
End With

Sending an Access Report as a PDF Attachment

One of the most powerful patterns is exporting a report to PDF and emailing it automatically:

Sub EmailReport(reportName As String, toAddress As String, subject As String)
    On Error GoTo ErrorHandler
    
    ' Export the report to a temp PDF file
    Dim pdfPath As String
    pdfPath = Environ("TEMP") & "\" & reportName & "_" & Format(Now(), "yyyymmdd") & ".pdf"
    
    DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, pdfPath, False
    
    ' Send via Outlook
    Dim olApp As New Outlook.Application
    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)
    
    With olMail
        .To = toAddress
        .Subject = subject
        .Body = "Please find the " & reportName & " report attached."
        .Attachments.Add pdfPath
        .Send
    End With
    
    ' Clean up temp file
    Kill pdfPath
    
    MsgBox "Report emailed to " & toAddress
    Exit Sub

ErrorHandler:
    MsgBox "Error sending report: " & Err.Description
End Sub

Method 2: CDO (Collaboration Data Objects) — No Outlook Required

If Outlook is not installed, use CDO to send email directly via SMTP. This works on any machine with network access to an SMTP server.

Sub SendEmailViaCDO(toAddress As String, subject As String, body As String, _
                    smtpServer As String, smtpPort As Integer, _
                    smtpUser As String, smtpPassword As String)
    On Error GoTo ErrorHandler
    
    Dim cdoMsg As Object
    Dim cdoConf As Object
    
    Set cdoMsg = CreateObject("CDO.Message")
    Set cdoConf = CreateObject("CDO.Configuration")
    
    ' Configure SMTP settings
    With cdoConf.Fields
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtpPort
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = smtpUser
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = smtpPassword
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        .Update
    End With
    
    With cdoMsg
        .Configuration = cdoConf
        .From = smtpUser
        .To = toAddress
        .Subject = subject
        .TextBody = body
        .Send
    End With
    
    Set cdoMsg = Nothing
    Set cdoConf = Nothing
    Exit Sub

ErrorHandler:
    MsgBox "CDO email error: " & Err.Description
End Sub

Bulk Email from a Query

To send personalized emails to everyone in a query result:

Sub SendBulkEmails()
    Dim db As Database
    Dim rs As Recordset
    Dim emailCount As Integer
    
    Set db = CurrentDb
    Set rs = db.OpenRecordset("SELECT Email, FirstName, InvoiceTotal FROM qryUnpaidInvoices")
    
    emailCount = 0
    Do While Not rs.EOF
        If Not IsNull(rs!Email) Then
            Dim body As String
            body = "Dear " & rs!FirstName & "," & vbCrLf & vbCrLf & _
                   "This is a reminder that your invoice of $" & _
                   Format(rs!InvoiceTotal, "0.00") & " is outstanding." & vbCrLf & _
                   "Please contact us to arrange payment." & vbCrLf & vbCrLf & _
                   "Thank you."
            
            SendEmailViaOutlook rs!Email, "Invoice Reminder", body
            emailCount = emailCount + 1
        End If
        rs.MoveNext
    Loop
    
    rs.Close
    MsgBox emailCount & " reminder emails sent."
End Sub

Scheduled Email Reports

Combine email sending with Windows Task Scheduler for automated scheduled reports:

  1. Create a VBA procedure that generates and emails the report
  2. Create a macro that calls the procedure
  3. Create a command-line shortcut: "C:\Program Files\Microsoft Office\...\MSACCESS.EXE" "C:\Database.accdb" /x MacroName
  4. Schedule the shortcut in Windows Task Scheduler

This runs Access in the background, executes the macro, and closes — no user interaction required.

Conclusion

Email automation from Access transforms a passive database into an active communication tool. The Outlook automation approach is the most reliable for most business environments and supports HTML emails, multiple recipients, and attachments with minimal code. Add email notifications to your key workflows — new record alerts, overdue reminders, scheduled reports — and your database will deliver value proactively rather than waiting to be queried.

Work With Access Evolved

If you found this article useful, Access Evolved specializes in exactly this kind of work — from hands-on Microsoft Access support to full database modernization projects.

Want to replace your Access VBA email automation with a more reliable modern solution? Schedule a free call and explore your options.

Schedule a Free Call →

Thinking about migrating?

Ready to move beyond Microsoft Access?

Access is a great starting point, but growing businesses often hit its limits. Anthony Passeri specializes in migrating Access databases to modern platforms — Power Platform, Power Apps, SQL Server, Azure, and more — so you keep your data and workflows without the headaches.

A

Written by

Anthony Passeri, MBA

Access Expert and Editor

Bridging the gap between Access and the Future

Explore Topics

#vba#email#outlook#automation#notifications

Keep reading

More on VBA & Macros