How to import or create an Outlook 2003 rule (.rwz) with VSTO 2005?

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!

29.07.2009 15:01:26
2 ОТВЕТА
РЕШЕНИЕ

This cannot be done programmatically using the imported RWZ. You can create rules programmatically though. You can use CDO/RDO etc. or using the OOM directly inside an addin or macro. All slightly different degrees on things you can do. Take a look at:

MSDN DEV Reference
http://msdn.microsoft.com/en-us/library/bb176397.aspx

How to: Create a Rule to Move Specific E-mails to a Folder
http://msdn.microsoft.com/en-us/library/bb206765.aspx

RDORules
http://www.dimastr.com/redemption/rdo/rdorules.htm

2
29.07.2009 16:33:55
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 30.07.2009 11:58:12
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 30.07.2009 12:51:56
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 30.07.2009 13:10:29
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 30.07.2009 13:34:00
I see... so I have the following options: 1. Spending money for a redistributable RDO license 2. Using VBA with a lot of trouble distributing it 3. Let my customer migrate from Office 2003 to 2007 ;) I believe the feature is going to die but nevertheless thanks for your help! :)
Marcus 30.07.2009 13:40:04

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)

-2
3.08.2009 22:37:48
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 31.07.2009 07:21:57
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 3.08.2009 22:25:09
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 3.08.2009 22:35:51
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 4.08.2009 06:57:51
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 4.08.2009 22:47:27