How to send an email in Outlook with VBA?

Applicable to Microsoft Outlook 365 / 2019 / 2016

Here’s a note we got from a reader:

Thanks for your very useful Outlook coding help. I am wondering if you can share some code to help automate sending an email in Outlook 365? I know that there are several ways to send recurring message but i am specifically interested in using VBA for my this task.

Thanks for the question. Automatically sending emails seem to be among the most useful and popular tasks you can automate using VBA. Read on for more details and a simple script to get you started here.

Sending Outlook emails using VBA

To send out email messages in Outlook using Visual Basic for Applications, proceed as following:

  1. First off, use the VBA Outlook object model to create a new email item.
  2. Then go ahead and set the message importance, recipients (separated by semi colons) and body text style and content.
  3. Next, display the message in your Microsoft Outlook application.
  4. Last, go ahead and send it your email recipients.

Here’s the simple VBA code to automatically create and send simple emails. Note that you are to easily improve this script to include file attachments, tasks etc’, but let’s start with a very basic script.

Sub SendMail()
Dim MyEmail As MailItem
Set MyEmail = Application.CreateItem(olMailItem)

With MyEmail
.To = "<type your recipient email address/ess here>"
.Importance = olImportanceHigh
.Subject = "<type the subject of your email here>"
.Body = "<type the email message text here>"
.BodyFormat = olFormatHTML
End With

'I purposely commented the next line, uncomment it by removing the "'" sign to send your email.
' MyEmail.Send
End Sub

Create a Outlook VBA macro shortcut

You might want to look into associating the VBA code you just wrote with a command button in Outlook. This will allow you to easily launch it from a shortcut placed in the Outlook Ribbon.

Here’s how to do that:

  1. First, go ahead and open Microsoft Outlook.
  2. Hit File then select Options
  3. Now go ahead and select Customize Ribbon.
  4. In the Customize Ribbon section, you’ll notice the Choose Commands from list box.
  5. Select Macros
  6. Then Select your newly created VBA code, in our case the name should be SendMail.
  7. Then hit Add and then OK. Optionally you might want to assign an icon to your Macro.
  8. Your Macro will be available in the Quick Access toolbar in the upper left side of your Outlook application.

Possible issues with VBA macro settings

Your Outlook macro settings might need to be tuned in order to run macros. If so, here’s how to do that.