Ty Anderson

Creating a custom Send button in Outlook

It’s large. It’s simple. It’s elegant. So much so that users can’t ignore it. Like a siren, it sings a beautiful melody saying “Click me!” It might just be the most popular button in the Outlook user interface. I speak, of course, of the Send button found in the MailItem inspector window (and also the TakItem and AppointmentItem… but not by default).

The Send button in Outlook

Given her conspicuous nature and popular status, it stands to reason that nerdy developers like us want to target this button and customize her behavior (this analogy works if you switch the button to a “he” and the developer to a “she”). In fact, it is a popular topic in forums, MSDN forums, and elsewhere.

The forum post typically resembles this:

“I want to create a custom send button in Outlook that [insert your custom business rules here]”

—OR—

“I want to add an additional send button next to Outlook’s default send button that [insert your custom business rules here]”

In the posts I’ve seen, the business logic is reasonable. What is less reasonable is how the forum question asker (aka the developer) wants to implement a custom send button.

Two options for creating a custom Send button of your own

Microsoft does not provide us with a way to customize the Send button using the Outlook object model. We can’t change its caption, size, colors, etc. This is just how it is. Microsoft is happy with the Send button as-is and doesn’t want us messing with it.

But, we are not without options. We have two options that allow us to display our own Send button in the inspector window.

Use the Windows API

The Windows API has all the methods we need to draw on the screen. We can draw objects and place them where we want. Thus, we can draw our custom button and place it over the Send button. Thus, the user will never see the default Send button in Outlook. They will see and click our button. We can respond to the click and execute our logic.

If you want to give this a try, be sure your client has the budget for it as it is filled with pitfalls. Pitfalls called “working with the Outlook and Windows API in the same solution”. I don’t recommend this option. Save it for when 1) the solution absolutely must have it and 2) there is plenty of time and budget in the project plan.

Build a custom Outlook form

Using this strategy, you build a custom form using Outlook’s form designer. This is no small customization. You will need to build a form that replaces the MailItem compose form. By replace, I mean you need to recreate the form in its entirety (excluding the Ribbon… although you can choose to replace the entire Ribbon too).

This strategy is time consuming also filled with potential pitfalls. For example, you need to configure Outlook to display your form when the user creates a new email. This might sound simple until you consider the various methods that display the mail form (ribbon buttons, command buttons, keyboard shortcuts, etc). Display the form is easy. Ensuring your custom send logic is invoked in all the possible places that allow a user to send an email is not-so-easy. You can find more details here:

Microsoft tutorial: Creating and distributing custom forms with Outlook

Add-in Express tutorial: How to create a custom Outlook form using VBA

These two options leave much to be desired. However, there is a third option and it works quite well.

The best practice is to use the ItemSend event

The ItemSend event is the proper place to invoke your custom send logic. This event fires when an Outlook sends an item on its merry way. The sending can be done via an Inspector’s Send button or via an Outlook item’s Send method.

The ItemSend event is a great place for your logic because it is a central location for items that Outlook sends elsewhere. You don’t need to worry about hooking your code to ribbon buttons, command buttons, keystrokes, etc. And if you combine it with some UI elements that inform the user your custom send logic will be invoked, you will have a sophisticated solution.

To illustrate my point, I created a sample Outlook add-in that logs all sent email in an Access database. In addition, the add-in implements a custom ribbon with a toggle button that enables/disables the database logging. Lastly, there is a custom pane that displays in the MailItem inspector if logging is enabled.

A sample Outlook add-in that logs all sent email in an Access database

There is very little code required to implement this idea. Here is the complete code listing of the ItemSend event.

Private Sub adxOutlookEvents_ItemSend(sender As Object, e As ADXOlItemSendEventArgs) _
    Handles adxOutlookEvents.ItemSend
 
    Dim mi As Outlook._MailItem = TryCast(e.Item, Outlook._MailItem)
 
    e.Cancel = False
 
    If Not IsNothing(mi) And logEnabled Then
        Dim cnn As OleDbConnection = New OleDbConnection()
        Dim cmd As OleDbCommand = New OleDbCommand()
 
        cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; "+ _
            "Data Source=E:\CustomSend\EmailLog.accdb;Persist Security Info=False;"ustomSend\EmailLog.accdb;Persist Security Info=False;"
 
        Dim sql As String = "INSERT into Emails ([TO], CC, [From], Subject, Body, SentOn) VALUES ("
         & ","
                Chr(39) & mi.#
        sql = sql & Chr(39) & mi.To & Chr(39) & ","
        sql = sql & Chr(39) & mi.CC & Chr(39) & ","
        sql = sql & Chr(39) & mi.SenderEmailAddress & Chr(39) & ","
        sql = sql & Chr(39) & mi.Subject & Chr(39) & ","
        sql = sql & Chr(39) & mi.Body & Chr(39) & ","
        sql = sql & Chr(35) & Date.Now & Chr(35)
 

The code sample begins by referencing the current mail item. Then, I set e.Cancel to False… just for show. I just want you to know you could set them to True and cancel the sending of the email. Next, I create a connection to the Access database and build a SQL statement. The SQL statement contains property values of the mail item. When the SQL statement is ready, I open the database connection and execute the query to create new email log entry.

*****

I’ve attached the sample code to this post so please download it and take a longer look at how I implemented this concept. It’s easy to implement and avoids the pitfalls and issues involved with the other two strategy. Occam’s razor wins again!

Available downloads:

This sample Outlook add-in was developed using Add-in Express for Office and .net:

Custom Outlook Send button sample (VB.NET)

You may also be interested in:

7 Comments

  • https://secure.gravatar.com/avatar/035ab6c41482bab76c544295e7dd1067?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Jitendra Gupta says:

    Hi Friends,

    i want to create another custom send button like as default send button just near to this.
    please help me how can i do this . i am using vs213 and office 2013.

  • https://secure.gravatar.com/avatar/ab4ec2858cfdf1e44dadf8c50fae314d?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Dmitry Kostochko (Add-in Express Team) says:

    Hi Jitendra,

    Ty made a good job of explaining all the knowledge we have on this subject in this post. I believe you can customize either of the described approaches for your needs.

  • https://secure.gravatar.com/avatar/8f56564dac7b1a50751cf3dd9be68e37?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Surender Singh says:

    Hi Ty, Can you please share how can we get the green pane(Email Logging Enabled) in a reading pane or inspector window like you have above?
    It doesnt looks like a view or form. What control is it and how can we use it?
    Thanks,
    Surender

  • https://secure.gravatar.com/avatar/c68f03884efb33fd95bcfbd9f1078c07?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Ty Anderson says:

    Hello Surender

    The green panel is an ADXOlForm. You can add one to your project using the Add New Item dialog and selecting the ADX Outlook Form template.
    You can find the template under the Add-in Express Items > Outlook node.

    This article has sample code at the end of it. Please take a look at it as well as this article:

    https://www.add-in-express.com/outlook-extension/outlook-folder-views-net.php

    Good luck!

    Ty

  • https://secure.gravatar.com/avatar/72ac3a50fbd4dff5bc90bda79708bb7d?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G MacsAre1 says:

    One observation. It appears that the item send event triggers when the email is sent, not when the send button is pressed. My IT department thought it was a good idea to force feed spell check on send down our throats by disabling the option to turn it off. I tried the ItemSend event to mark my text as NoProofing, but it acts after the spell check runs, so is useless. I looked into a custom form but that’s just too much work. The send button doesn’t even show up in the default custom form! For now I created a macro to send an email or meeting invite without spell checking and added it to the top left of the ribbon. Unfortunately I still hit the normal send button too often out of habit.

  • https://secure.gravatar.com/avatar/74d6387adbf20834101ee2e9e548e97a?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Hadeel says:

    hi
    if i had create a customized form in outlook 2013 and i need to add a send button to the form, can you you provide me with the steps to do this task .

    thanka a lot

  • https://secure.gravatar.com/avatar/c68f03884efb33fd95bcfbd9f1078c07?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Ty Anderson says:

    Hello Hadeel

    Before I answer, can you tell my why you want to replace to the Send button?

    Ty

Post a comment

Have any questions? Ask us right now!