Extend outlook rules Actions using vsto - c#

I Want to create custom code that will run when the user decides based on outlook's rules.
so far i checked a few possibilities:
1)Create a custom Action that would be added to the rules actions options - that is not possible according to MS - https://social.msdn.microsoft.com/Forums/vstudio/en-US/1bae2bbc-0ab4-419a-b0d6-7a02195348ce/outlook-custom-action-in-rules-wizard?forum=vsto
2)Run Script based on a rule - built in ability, however i encountered a few issues:
it is not possible to share the script
the macro's have to be enabled each time (disabled again when you restart)
I want to use the C# VSTO add-in in order to overcome those problems:
Is there a way to implant the script and make sure the macro is enabled using a VSTO add-in?
this way users will be able to install the add-in and then chose the script as an action to every rule they create based on the default outlook rules.

You don't need a rule if your code is in a VSTO addin. You can use Items.ItemAdd event on the Inbox folder or Application.NewMailEx event to so anything your please with the newly arrived message.

Related

Force an Excel file to be associated with a VSTO addin

This is my use case:
I need to develop a excel VSTO add-in that prevents a user from accessing a excel file unless the add-in is installed. This add-in basically authenticates the current user, and if that is successful, it will grant them access to the file. Basically I need a way to protect a file that uses my own authentication (and not the built-in password protection provided by Microsoft. Why? Because I need to be able to revoke access to the file and a local password would prevent me from doing so)
I know how to write the add-in, what I don't know is, how do I force a file to be associated with that plugin? I tried using a custom property, but that is very hack-able. Basically, I would have a custom property that says: "use this add-in", but a knowledgeable user could just go in Advanced Properties and simply delete it.
My suggestion would be for you to use COM Add-ins, as they do not distribute the code to the user and can't be easily hacked. A simple Add-in, that uses .XLA or .XLAM files are simply password protected VBA projects that can be hacked.
Now, for your workbook, I suggest you encrypt and scramble all the data and use your COM Add-in to decrypt your data and use a function to prevent saving the workbook un-encrypted. You could just override the Workbook_OnSave method to encrypt on saving. Also disable copying of cell values.
For this part, I don't know if this is possible, but you would need to override user access to VBA editor, so they couldn't walk around your add-in protections and also disable the access to options menu to disable the Add-in. That can be achieved by overwriting the Excels shortcut keys and hiding the menu bar.
Again, for the last part, I don't know if it's actually possible to limit user access to VBA editor. I think it would be pretty similar as limiting access to Add-in controls by overriding ALT+F11 shortcut and just hiding the developers tab as a whole.
Well that's my two cents, good luck!

Communication between VSTO and .XLL

In Visual Studio, I have a solution. In that solution I have 2 projects. One is a VSTO so that we can make a plugin for Excel. The other project is for creating a .xll file so that we can have Custom Functions.
The VSTO helps us create a login system on excel so that they can do certain things.
However, since we only want our users to be able to use our custom functions they have to log in. I think that these 2 projects can't communicate directly so the .xll addin wouldn't know if a user is logged in or not.
Is there anyway for these 2 projects to communicate? Perhaps via a middle-man like a class with static variables?
EDIT:
More information:
Both projects are written in C# code. I was able to do that for the .xll file by using ExcelDNA.
So if there's any way that I can create maybe a C# class that can coordinate or share data between the two projects that would be really great. Since login data isn't the only thing that we want to share.
I'm hoping in the class there would be a static boolean variable holding whether the user is logged in. So the VSTO could set the boolean value and the .xll could get it.
You could add a hidden function [ExcelFunction(IsHidden=true)] to the .xll, which you can call from the VSTO add-in with Application.Run.
I would use a licensing system that let the user validate a licence key. This process can takes place within the VSTO. Then I would use two checks :
if in the VSTO the licence key is validated then load the xll, otherwise do not load it.
within the xll, by using relative path, I would locate and check a second time the licence key (to prevent that the user loads directly the xll).
It just requires to be able to check the licence key in C# (VSTO) and C (Xll), ie to have a validation key algorithm implemented in both languages.

Undo action for Excel addin

How does undo work in Interop.excel? C# - making a addin in VS
I imagine the following:
I register a undo-method on the stack (implemented by me).
I save the current state... where?
When the user uses undo (ctrl-z), my undo-method gets called, and I restore the previous state with the data that I stored.
Can't get any good info on this though. Maybe it works totally different?
You could look at NetOffice http://netoffice.codeplex.com/ They are tutorials how to create your own Add-In. You can work with VSTO, download the NetOffice .dll which you need to write your own Excel Add-In and to design it as you wish and implement your functionalities.

Deploy/programmatically create Outlook Rule to run Script

I need to deploy an Outlook rule that runs a script. So in other words I need deploy both an Outlook rule and the script it runs. I know I can get users to import the rwz rule file and maybe paste in the script, but I wondered if there was a more user friendly way.
I started writing a C# program to create the rule, but I cannot see a way to set the action to run a script. Is this possible?
Cheers, Jamie
The library https://github.com/hughbe/OutlookRulesReader contains a specification and reference implementation library (in Swift) for reading and writing Outlook Rules Files
A full description of the format can be found here
The Rules Wizard (and .rwz files in particular) are a dead end as far as deployment is concerned.
According to the MSDN article on Specifying Rule Actions, the "start a script" rule cannot be created programmatically, so that's not an option either.
You need to start looking into different options. As going the C# way seems an option, those include:
Replacing the "rule" by an add-in that handles the same events that trigger the rule conditions, the executes the desired "script" code.
Replacing both the rule AND the script by the add-in.
If you are on Exchange, there are rules and triggers on that level too that have some more options.
We can't really advice you on the most appropriate route unless you share some more detail on what it is your rule and script are doing.
Based on the work of Hugh Bellamy, Outlook Redemption library (I am its author) as of version 6.0 fully supports client side rules (along with import and export of RWZ files) through the RDOClientRules collection.

Reading mails from outlook programmatically using C#

I am trying to create a program that reads my mail from Microsoft Outlook so that I can move them into different folders based on thier contents. I am using Microsoft.Office.Interop.Outlook 12.0, which works fine with Outlook 2007.
How do I handle scenario where another user uses Outlook 2010?
Do you need to use C#? If you don't need to use C#, you can open one of the messages that you need to move and click on "add rule". There you can define rules to, for example, move all mail from your boss into a folder called work. I don't see why you need to use C#. It would be very difficult to do that in C# except simulating mouse movements...

Categories

Resources