I met Roger Guess (@RogerGuess) on Twitter this morning when I responded to one of his tweets. Roger’s tweet asked if there was some way in Outlook to have a visual reminder of the account an item is being sent through. Roger explained that he needs this to avoid sending message through the wrong account.
Outlook does provide a visual cue in the form of a warning that appears directly above the Send button for any message that’s not being sent through the default e-mail account. The warning says “This message will be sent via .” Since this warning does not appear for messages being sent via the default account it does act as a warning. If the warning does not appear, then you’re sending through the default account. If it does appear, then you know you’re sending through one of your other accounts and the warning tells you which one you’re using.
I explained this to Roger who replied that he needs a more obvious warning. The solution I propose is to use a small script to display a pop-up dialog-box asking Roger to verify the account to send through. This script will be triggered each time Roger sends an item. For each outbound item a dialog-box with the prompt “Are you sure you want to send the message through the account?” will appear. If Roger clicks the Yes button, then the message will send via the selected account. If instead Roger clicks “No”, then the code will cancel the send giving Roger the opportunity to select a different account for it go out under.
Instructions.
Outlook 2007.
- Start Outlook
- Press ALT+F11 to open the Visual Basic Editor
- If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
- Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
- Edit the code as needed. I included comment lines wherever something needs to or can change
- Click the diskette icon on the toolbar to save the changes
- Close the VB Editor
- Click File and select Options
- When the Outlook Options dialog appears click Trust Center then click the Trust Center Settings button
- Click Macro Settings
- Select either of the two bottom settings (i.e. “Notifications for all macros” or “Enable all macros (not recommended; potentially dangerous code can run)”. The choice of which to chose is up to you. If you select “Notifications”, then you’ll be prompted at times to enable macros. If you pick “Enable all” then there’s a chance that a malicious macro could run. It’s a question of how much risk you want to assume.
- Click Ok until the dialog-boxes have all closed
- Close Outlook
- Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.
Outlook 2010.
- Start Outlook
- Click Tools > Macro > Visual Basic Editor
- If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
- Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
- Edit the code as needed. I included comment lines wherever something needs to or can change
- Click the diskette icon on the toolbar to save the changes
- Close the VB Editor
- Click File and select Options
- When the Outlook Options dialog appears click Trust Center then click the Trust Center Settings button
- Click Macro Settings
- Select either of the two bottom settings (i.e. “Notifications for all macros” or “Enable all macros (not recommended; potentially dangerous code can run)”. The choice of which to chose is up to you. If you select “Notifications”, then you’ll be prompted at times to enable macros. If you pick “Enable all” then there’s a chance that a malicious macro could run. It’s a question of how much risk you want to assume.
- Click Ok until the dialog-boxes have all closed
- Close Outlook
- Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim olkPA As Outlook.PropertyAccessor, strAccount As String, intPos1 As Integer, intPos2 As Integer If Item.Class = olMail Then If msgbox("Are you sure you want to send the message through the " & Item.SendUsingAccount & " account?", vbYesNo + vbApplicationModal, "Verify Sending Account") = vbNo Then Cancel = True End If Else Set olkPA = Item.PropertyAccessor strAccount = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E28001E") intPos1 = InStr(1, strAccount, Chr(1)) intPos2 = InStr(intPos1 + 1, strAccount, Chr(1)) strAccount = Mid(strAccount, intPos1 + 1, intPos2 - (intPos1 + 1)) If msgbox("Are you sure you want to send this item through the " & strAccount & " account?", vbYesNo + vbApplicationModal, "Verify Sending Account") = vbNo Then Cancel = True End If Set olkPA = Nothing End If End Sub
Notes.
- This solution is only for Outlook 2007 and later. Outlook’s object model for 2003 and earlier did not have the SendUsingAccount property.
- I modified the code on 1/30/2012 to handle items other than emails (e.g. meeting requests). Unfortunately, they don’t have a SendUsingAccount property, so I had to improvise. My solution is to use the PropertyAccessor object to read a property directly from the MAPI object. It appears to work, but as with all improvised solutions it may be subject to problems.
Revisions.
- Revision 1
This revision is for Hugh who asked if it’s possible to be prompted to verify the account only when an item is not being sent through the default account. The answer is “yes”. All we need to do is alter the logic a bit to compare the account an item is being sent through to the default account. If the two don’t match, then display the verification dialog-box. The code does nothing for items sent through the default account.
All Hugh needs to do is use this code instead of the code in the original post. The same instructions apply. As with the original post, this solution only works for Outlook 2007 and later.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim olkPA As Outlook.PropertyAccessor, strAccount As String, intPos1 As Integer, intPos2 As Integer If Item.Class = olMail Then If Item.SendUsingAccount <> Session.CurrentUser.Address Then If MsgBox("Are you sure you want to send the message through the " & Item.SendUsingAccount & " account?", vbYesNo + vbApplicationModal, "Verify Sending Account") = vbNo Then Cancel = True End If End If Else Set olkPA = Item.PropertyAccessor strAccount = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E28001E") intPos1 = InStr(1, strAccount, Chr(1)) intPos2 = InStr(intPos1 + 1, strAccount, Chr(1)) strAccount = Mid(strAccount, intPos1 + 1, intPos2 - (intPos1 + 1)) If strAccount <> Session.CurrentUser.Address Then If MsgBox("Are you sure you want to send this item through the " & strAccount & " account?", vbYesNo + vbApplicationModal, "Verify Sending Account") = vbNo Then Cancel = True End If End If Set olkPA = Nothing End If End Sub
This is an old thread and I’m wondering if it has been / needs to be updated to be used successfully in Outlook 2016?
Hi, Adriennelisa.
That code works fine in Outlook 2016 as is. No changes are necessary.
Hi David, I am sorry for this maybe stupid question but I am a total rookie to VBA: Which parts of code do I have to edit to get the macro to work? Thanks a lot, Mary
Hi, Mary.
This code does not require any editing. All you need to do is follow the instructions for your version of Outlook.
Thank you. This is just what I was looking for, PERFECT!
You’re welcome, Steve! I’m glad you like the solution.
Hi David,
First of all thanks for all your work.I have 2010 office and i tried the code snippet revision but have not had any luck.I want to have a popup if i am not sending the email from my email address i.e i should get a pop up whenever i reply via shared mailbox.
Thanks in advance
Regards,
Rahul
Hi, Rahul.
You’re welcome!
What does “shared mailbox” mean in this context? If you open a sent item that was sent via the shared mailbox, what address does it show for the sender?
Thank you for this clean and simple solution. I searched all over the web for this type of prompt and yours worked first time right out of the chute. BTW, I am not a programmer or very techie at all. The instructions were great with one exception: The Trust Center is under Tools in my 2007 version of Outlook. All else was perfect and an elegant solution.
Cheers!
You’re welcome, Bruce. I’m glad you like the code.
David,
Any chance of you helping me get this code onto my computer remotely? It does not seem to be working for me.
Richard
Hi, Richard.
Possibly. Tell me a little about your environment. What version of Outlook are you using? Have you enabled macros? Are you getting any error messages?
Hi David,
Outlook 2007. I did what you suggested in your instructions and the macro did not take for some reason. I am not a computer “buff” so it might be just a simple fix. If we could set up a time I would let you get on my PC through Team Viewer and you could do this as I haven’t got the time to spend troubleshooting.
I enabled macros and did not get any error message. I tried sending a couple of test e-mails and they went out as usual with no pop up alert.
Let me know if you are available to give it a try remotely.
Thanks
Richard
What time zone are you in, Richard?
Eastern
How about between noon and 1:00pm one day next week?
Sure David. How does Wed or Thursday Aug 22 or 23rd look for a noon call? Also would you like to call me or shall I call you? Lastly before I give you my phone number I want to make sure it does not go out on your “public” site post. Please advise if this reply is going directly to you or can others read it.
Thanks
Richard
Anything you post here would be public. I’ve emailed you.
Hi David. I am getting a Compile Error: Ambiguous name detected: Application_ItemSend – when I send any email now. It opens the code page expecting a fix. Do you know what I can do to resolve this? Thanks!
The error is telling you that there’s already a procedure there called Application_ItemSend. You’ll need to merge the code from the two procedures into one procedure.
Thanks David. When I start Outlook now, the macro warning doesn’t show anymore, but the settings are correct to have it show when launching Outlook. Any ideas? I really appreciate your wisdom David! Thanks.
I have inserted the code into the other procedure and compiled with no errors. However, after restarting Outlook, (and manually enabling macros with alt + f11), when I send an email, I do not get the opportunity to select an account to send from. Should I email you the code I am using? Thanks David.
Hi, mannagod7.
Sure, email me the code (in a text file attachment, please) and I’ll take a look. What version of Outlook are you using?
David – This is great. I have 3 differrent accounts in 2010, 2 pop & 1 Exchange. My only issue is that I used the 2nd code sample and it prompts me for all accounts. Even if I send from my default account it still prompts me. Do I need to customize the 2nd snippet?
Thanks
Hi, Kirk.
Thanks!
By “2nd code sample” I assume you mean the code in Revision 1. If so, then the reason the code is prompting you on every message you send has to do with how Exchange works internally. Exchange uses X.400 addressing internally. That means the code is comparing your X.400 address to your SMTP address which, of course, doesn’t make for a match. The solution is to edit line #15 of the code. Change it to
Now the code will compare an SMTP address to your primary SMTP address which should mean that you aren’t prompted when sending a message through the default, Exchange, account.
Thanks David.
Actually one of the POP accounts is my main account. I’ve gotten used to it prompting for all accounts so I think I like it as is.
Thanks again for your time.
Kirk
You’re welcome, Kirk.
Neat script. Is it possible to only have the dialog box pop up when trying to send from an account other than the default account? My problem is 98% of the time I am and should be sending from the default account. Its the stray email that came in unnoticed, to a different account, that I need to be concerned with when replying.
P.S.- On my outlook 2007, I needed to select Tools:Trust Center (vs. File:Options:Trust CEnter: Trust Center Options per the instructions).
Thanks, Hugh.
The answer is yes. I added a revision to the post (it’s at the bottom) showing how to do this.
Hello David
This is exactly what I’m looking for, and it’s all working except for when I send a meeting request out (which is one of my problems – I’m always sending meetings from the wrong account!).
When I send a meeting request it fails with a “Object doesn’t support this property or method” error. It;s failing on the “Item.SendUsingAccount”.
How can I modify this code to also work with meeting requests?
Thank’s in advance for any assistance you can provide
Charlie
Charlie,
I’ve modified the code to work with meeting requests. Please replace the code you downloaded earlier with the current version. Give it a try and let me know if that fixes the issue.
Cheers!
Good morning David,
You really don’t have to apologize, I mean : who still use office 2003 nowadays ?
If you can come up with a solution for 2003 that would be indeed great but there is no hurry.
I really apreciate, so want to thanks again for your time.
Hello David,
First, thanks a lot for your script it’s is exactly what I need.
Outlook and exchange 2003 in the compagny… several mail box by users and they always send mail via the main account and that ‘s quite bad…
I know nothing about VB :
So I follow the instruction and copy the code in “this outlook session” and save it but when I try to send mail I always get :
erreur 438
Propriété ou methode non gérée par cet object.
I did not modify anything in the script to be sure to not screw it.
Outlook is 2k3 SP3 –> french version
VBA is version 6.3
Did you know what is happening ?
Hi, Elisa.
The error is a result of your version of Outlook. Outlook 2003 doesn’t support the SendUsingAccount property. That was added in Outlook 2007. I apologize for the confusion. I should have indicated in the post that this was only for Outlook 2007 and later. It may take a few days, but let me see if I can come up with a solution for 2003.
Pingback: Reminding Users to Include "from" field
Fantastic little script – exactly what I was looking for, and it works! Thanks David.
Thanks, Sabina. I’m glad you like it.
Rather than nag the user to select the account (as this script does), do you know of a way to programmatically set the account?
Outlook is able to receive mail from multiple POP3 accounts into one Inbox and reply using the appropriate account, but with IMAP it creates an Inbox per account which is unwieldy (Gmail manages to handle multiple IMAP inputs to a single Inbox somehow). If I transparently redirect multiple accounts to a single IMAP inbox which I then collect using Outlook, Outlook sends everything through the IMAP account, even when I create send-only accounts (POP3/SMTP with retrieval disabled in Send/Receive Groups) corresponding to the other addresses.
I’ve seen one approach which hooked the NewMailEx event and used the Redemption library to change the Account property of incoming MailItems (which should in effect be similar to receiving emails through a POP3 account and then moving them into the IMAP inbox), and another which hooked the MailItem.Reply event to set the correct sender using SetSendingAccount, but both were written for previous versions of Outlook and I haven’t been able to get them to work under 2010.
Update – I put the code in ThisOutlookSession and it worked. Any reason against putting it there? Thanks.
Hi, Anthony.
Oops! You found an error in my instructions. ThisOutlookSession is where the code belongs and where the instructions should have told you to put it. I’ve modified them to correct that error. Sorry about that!
I can’t seem to get the macro to work. Is there anything I can check or any troublshooting to try? I am new to vbs so I dont know a lot. Thanks.
Hi, do you know if there’s a way to change Outlook signature automatically based on From: field?
Checkthis questions on EE : http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_26768602.html
Hi, Thomas.
Yes, that’s possible. I’ve posted my solution to the question on EE. I’m BlueDevilFan there.