I'm writing an Outlook 2016 VSTO Add-in in c# to add some lookup functionality. I already managed to create a context menu item when right clicking in an email body. The code in the handler accesses the current selection and executes my lookup functionality. So far so good.Screenshot of working context menu
Now I also would like to add an item to the context menu when right clicking on the email subject (in the reading pane above the body). Although looking in "Office2016FluentUserInterfaceControlIdentifiers" I couldn't find the idMso.
Question 1: What is the idMso of this context menu?
Next problem is here that it also seems difficult to access the current selection - the way via ActiveInspector.WordEditor.Application.Selection.Text or ActiveExplorer.Selection[1].GetInspector.WordEditor.Application.Selection.Text did work for the Email body but not for the subject above.
Screenshot of selected text in subject
Question 2:How to access the current selection in the email subject?
Any help is appreciated.
Preview pane body - use Explorer.ActiveInlineResponseWordEditor.
Subject edit box - the best you can do is use Windows API to find the control's HWND and then retrieve the selection using EM_GETSEL message.
Related
we have a working outlook form in our company which includes a button in outlook ribbon
By clicking it a New Mail window opens which has the designed custom form with some combo-boxes, the printscreen image is attached
Below this form there are some VB Macros which fills the combo-boxes and runs some code and when we click Send, a new mail which has this form will be sent for the recipient(s) The Problem is: the recipient receives the vb macros behind this form and sometimes this macros will be accidentally modified and ..., so we don't like this approach
Currently I'm working on a C# VSTO project to replace a AddIn(.dll) with this macro.
My first solution: I have imported a copy of the custom form as a form region and add combo-boxes and other controls in it and fill them and everything was ok, but this form have not been sent by mail to recipient!
My Second solution: I think it would be better to remove all macros from the old custom form and try to fill combo-boxes of the old custom form in my AddIn.
My Question is which solution is better? Is there a better way to do this?
I think I'm going wrong direction because of lack of knowledge with VSTO and outlook forms. please help
Outlook custom forms is an old approach. Defintely, form regions is the better way to go. But it requires better coding skills. Be aware, Outlook form regions can't be sent to recipients with the item.
You need to have the Outlook add-in installed on both sides (sender and recipients) if you want to see the data entered on the form region. Moreover, you have to create corresponding user properties on the item being sent. On the recipient side your add-in can handle the NewMailEx event of the Application class which is fired when a new item is received in the Inbox. So, you may read user properties and display on the form region. Also you may consider using any web server (web service) for uploading such data there. In that case you will be sure the data is preserved when user properties are truncated on the recipient side.
The Add In
I have written a VSTO Add-In for Outlook. The crux of the add-in is to put a button on the Ribbon when a user is replying to email that will allow them to quickly set the Email Sensitivity to Confidential or back to Normal. Currently the process to do this on an email is multiple steps, and my client wants it to be one click. The button icon is Red or Green based on the sensitivity of the current email.
Sensitivity = Normal => Red Button
Sensitivity = Confidential => Green Button
There are a few basic use cases I have uncovered:
A user Creates a new Email
In this case the button should start Red and change when clicked.
A user Creates a reply to an email
In this case the button should start the same color as the parent email. If the parent email was Red, the button should be Red and if it was Green the button should be Green
A user Edits a draft
If the user has a draft the button should reflect the value of the Sensitivity property of the saved draft.
The way I chose to accomplish this was with two buttons in a ribbon XML where I override the getVisible property and based on the current MailItem set the appropriate button visible. Another way would have been to have one button and toggle the image and functionality based on MailItem sensitivity property.
Regardless of my choice I think I would have run into the same problem in that the Office Ribbon is meant to be a static object, drawn once at creation of the Explorer or Inspector and you need to force a redraw by calling the InvalidateUI method.
With that in mind, to cover my 3 use cases above I had to hook into some events from the application.
I'm not sure I can post the exact code, but the basics of it are as follows:
On Startup subscribe to:
Application.ActiveExplorer().SelectionChange
Application.Inspectors.NewInspector
On SelectionChange
If there is one item selected, and that one item is a MailItem
Refresh the Ribbon UI - Call Ribbon.InvalidateUI();
On NewInspector
If the Inspector.CurrentItem is a MailItem
Refresh the Ribbon UI - Call Ribbon.InvalidateUI();
The SelectionChange event handler covers if a user is clicking around in Outlook 2013 and up and selects an Inline Draft. It will draw the ribbon in the TabSet TabComposeTools, TabMessage. This places the icon on the main outlook window Ribbon when necessary.
The NewInspector event handler covers if the user double clicks on the draft, creating a new window.
The Problem
I have been receiving reports of Outlook crashing. At first I had limited logging and relied on the Event Logs generated by Outlook. Not very helpful.
Then I implemented log4Net, and I'm writing to a log file in the AppData folder of the user's profile. This has given me some insight
I have wrapped a try/catch around every method code block, so nothing in my add-in (that I wrote) runs outside of a try/catch, and each block just catches Exception, logs it, and throws it. This is an attempt to find the problem.
My latest log shows the UI refreshing, so it called my GetVisibility override, in there based on if the control.Context is an Explorer or Inspector I get the ActiveInlineResponse or CurrentItem as a MailItem, read the Sensitivity property and based on that return True or False if the button calling the handler should be visible. (I have one handler for both buttons)
The crash appears to happen when I am casting an ActiveInlineResponse to a MailItem. The next item in my log is the logging I do in the Startup handler of the Addin. (So the user restarted Outlook)
Other Details
The user base is currently running Outlook 2010 - Outlook 2016.
We have one add-in that runs on all of them as nothing we are doing should be specific to any version of office.
The add-in works without fail on Outlook 2010.
The add-in project selected was Outlook 2013-2016.
I'm using Ribbon XML over Designer because Designer doesn't support putting buttons in TabSets.
Update
I have put in some event handler local variables to my Add-In class as described by https://www.experts-exchange.com/questions/27305112/Problem-with-VSTO-event-handler-going-out-of-scope-in-Outlook-AddIn.html I haven't seen the error since, but also haven't had much feedback as I did this on a Friday and this Monday is a holiday. I'll update with an answer if this appears to be a "Fix".
I have an Outlook add in that was written with Outlook 2010 in mind but I am updating to handle Outlook 2013 correctly. As part of the add in I have included a number of context menu buttons using the IRibbon method.
At this point these new menu items work correctly, however I wish to remove one of the default Outlook contxt menu buttons with right clicking on a mail item or document in a specific folder.
I have tried declaring a GetVisible event for the button in the Ribbon XML but this does not get fired like the GetVisibile calls I have for my new custom added buttons.
If anyone has any hints, tips or experience with disabling one of the default Outlook 2013 context menu options they would be much appreciated.
Having looked into this further, the "Delete" option I was looking to remove was a new addition on 2013, having originally thought the add in I was working with had removed it in 2010.
It shares the same behaviour as the "Delete" button in the main top ribbon and appears to be a menu item that cannot be removed on an item type basis, but you can suppress the behaviour of the button within the add in.
So, I want create add-in which can read selected word at email and send it to the API by clicking on context menu. As for text selection everything is clear. But I stuck in creating context menu.
I search the web and found that we need add contextMenu item into the ribbon xml with specific idMso
But which of then I don't understand.
P.S.
I found the document with Outlook controls names here http://www.microsoft.com/en-us/download/confirmation.aspx?id=6627
Ok, I found it! idMso="ContextMenuReadOnlyMailText"
I'm currently working on an Outlook 2010 Add-In with C#. Is there any way to customize the "From/To/CC/Subject" pane in Outlook 2010?
Specifically, I hope to implement the following functionality:
Add a new field below the subject of an email
Add two icons on the right of that area
I need to do that both for email previews and when reading an email in a new window. See this ImageShack pic as an example.
You cannot customize this part of the Outlook user interface - as of my researches I've done for a client who just requested that. Here's my link list (with negative results):
How to customize Email Send button in Outlook?
Add controls to existing ribbon group in Office (VSTO)
Modifying Built-in Ribbon Controls
Add a control / button inside the group - Ribbon Bar
Outlook addin to add a custom "Send" button next to existing Send button in mail compose window
how to place a button next to the send mail (system button)
Can I add a custom “Send” button to Outlook?