views:

638

answers:

2

I would like to automatically create an Outlook rule (move email containing something in subject to folder xyz) but dont know how to achieve this. Of course I can create the rule and export it to a .rwz file. This file can be imported manually, but how can I import it automatically?

Can I import a rule through my VSTO 2005 Outlook (2003) Addin? Or can I create the rule from within this addin?

Thanks in advance!

A: 
76mel
Correct me if I'm wrong, but to create a rule programmatically I need to use VBA instead of VSTO. I have also read that VBA code can be run from VSTO but only since VSTO3. Is there a way to create my rule with VSTO 2005 SE ? (In VSTO 2005 SE is no Outlook.rules :/ )
Marcus
You can create them in your vsto or vba (i.e macro in outlook)It just depends on how you want to do this via macro, via addin or via standalone.
76mel
Actually my goal is to create the rule without having the user to do something. I would like to create it from within my VSTO 2005 SE Outlook addin, but as I have found out, you can create rules only for Outlook 2007 and not for 2003 (in case of VSTO development). Can you explain how I can create the rule for 2003 (without having the user to do anything else than maybe starting a setup or a script) ?
Marcus
Ok, You can use RDO in your addin, the VBA way has problems in distribution there are hackky ways to roll vba out via Copying VbaProject.otm
76mel
I see... so I have the following options:1. Spending money for a redistributable RDO license2. Using VBA with a lot of trouble distributing it3. Let my customer migrate from Office 2003 to 2007 ;)I believe the feature is going to die but nevertheless thanks for your help! :)
Marcus
A: 

A rule is just a way for the non-programmer to achieve what the programmer can already achieve with use of the Outlook Object model/CDO/.net/etc

I suggest you reevaluate the exact functionality you are trying to achieve and consider if it is really that essential to use a rule instead of a custom method (vsto, com addin, ext. automation of outlook, etc)

Anonymous Type
The advantage of using a rule instead of letting the Addin doing all the work is that the functionality of moving the Emails is also given in case the Addin is deactivated which might happen sometimes in my case. By having a rule it is more ensured that the mails will only be in the subfolder so that my Addin could parse them from there and does not need to filter the whole inbox which takes much more time. And I don't think that security is the problem since you can create rules with VSTO but only since Outlook 2007. However, presumably we will do it by using VSTO methods only ;)
Marcus
The problem with that is that the rule is still only client side. ie. Outlook still needs to be opened and running for your rule to run. Unless you have a badly written addin (that self-deactivates at runtime) the addin will always be loaded and running when a rule of the same nature could have been loaded and running.
Anonymous Type
Also note that none of the references (links) given in the "answer" above actually answer the question. The reality is that there is no way to programmatically import a rwz and create a rule with code. workarounds like "do it in vba" and use "rdorules" do not answer this question.FROM dimastr.com (the source of RDORules)....Important note: rules created by RDORules are not visible in Outlook (Tools | Rules and Alerts). RDORules collection only works with the Exchange Server rules; it cannot access and manipulate local rules (such as those used by a PST store).
Anonymous Type
Usually the addin will be loaded and running thats quite true but the user could deactivate it manually and this might happen sometimes. You are also right by saying that there is no way to import rwz programmatically but whats your point? I asked wether it is possible to import them or to create it by code. 76mel said that I cannot import it but showed a way of creating them (in Outlook 2007 its no problem to create rules). So its an correct answer to my question ;)
Marcus
actually no its not. Your question refers to outlook 2003, and besides all the workarounds provided to you do not create rules that can be interactive from the users perspective in the UI. As you say with 2007 this is no longer a problem, however afaik you won't get a proper "rule" using VSTO and OL 2003.
Anonymous Type