Create a Prompt When Sending Mail via Outlook
I have multiple accounts set up on my Outlook. For the most part when I send mail I use my Default account. Not an issue…except on that rare occasion when I accidentally send out an e-mail from the wrong account.
Well I have fixed the problem. I decided to create a prompt that would help remind me that I need to choose the correct account for sending the e-mail address.
With some help from this guy’s post, I reworked his code to be a simple prompt. Below are the steps on how to add this to your Outlook.
ThisOutlookSession
You need to create a function that will run right when you click the submit button in your mail window. In order to do that we need edit the current session of Outlook. We do that by accessing the ThisOutlookSession object.
- If you haven’t installed the Developer Tab in your outlook you can find instructions here.
- Click on the Developer tab and all the way to the left you will see a the Visual Basic editor icon.
- Click on that. The Visual Basic Editor will then open up. Expand the “Microsoft Outlook Objects” folder. You will then see the “ThisOutlookSession”.
- Open that up by double clicking on it.
- In the Editor you can add the following code.
1: Public blnSend As Boolean
2:
3: Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
4: If TypeOf item Is Outlook.MailItem Then
5: blnSend = False
6: Load formAccountMessage ' Load account list form
7: formAccountMessage.Show
8: If blnSend Then
9: ' send the mail
10: ' you can also add some checks to the
11: ' mail message you are sending here
12: Else
13: Cancel = True
14: End If
15: End If
16: End Sub
- That is it for this section.
Form Control
Now we need to make a pop-up to tell us we are about to send the e-mail and remind us to check the account being used.
- Create a new form item, name it formAccountMessage
- Now you can style that form how ever you want. Here is what I did.
- Now all you need to do is link up the buttons to some actions. Below is the code I used
1: Private Sub btnCancel_Click()
2: formAccountMessage.Hide
3: End Sub
4:
5: Private Sub btnSend_Click()
6: ThisOutlookSession.blnSend = True
7: formAccountMessage.Hide
8: End Sub
- That’s it. Just a simple reminder that helps you check before you send.
Helpful Tips
- Naming conventions are important if you are just copying the code and hoping it will work. Double check you have renamed your buttons and form name.
Cancel button = btnCancel
Send button = btnSend
Form name – formAccountMessage
- Make sure you enable macros to be used on your Outlook.
- Restart your Outlook to take effect.
Comments are currently closed.