Geeks With Blogs
Pranav`s TechNiche technical thoughts of a coffee addicted developer

Getting Rules from an exchange account configured in Outlook is pretty easy if we understand the hierarchy of the API. I banged my head for 2 days to get the exact function and attributes to get them. Keeping it here hoping that it will help someone who are searching for the same.

Dim olRules As Outlook.Rules = Globals.ThisAddIn.Application.Session.DefaultStore.GetRules

For Each olRule As Outlook.Rule In olRules
If olRule.Conditions.From.Recipients.Count > 0 Then
Dim exUser As Outlook.ExchangeUser = olRule.Conditions.From.Recipients.Item(1).AddressEntry.GetExchangeUser
Dim FromEmail As String = exUser.PrimarySmtpAddress
MessageBox.Show(“FROM:  ” & FromEmail)
ElseIf olRule.Conditions.SentTo.Enabled Then
Dim exUser As Outlook.ExchangeUser = olRule.Conditions.To.Recipients.Item(1).AddressEntry.GetExchangeUser
Dim ToEmail As String = exUser.PrimarySmtpAddress
MessageBox.Show(“TO: ” & ToEmail)
ElseIf olRule.Conditions.Subject.Enabled Then
MessageBox.Show(“Subject: ” & olRule.Conditions.Subject.Text)
End If
If olRule.Actions.Item(1).ActionType = Outlook.OlRuleActionType.olRuleActionMoveToFolder Then
MessageBox.Show(“Move To Folder: ” & olRule.Actions.MoveToFolder.Folder.FolderPath)
End If
Please note that this is a sample code generated as an illustration of getting the values from the attributes ONLY.
This code is NOT intended to show best practices or ideal code.
Posted on Wednesday, June 30, 2010 12:18 PM VSTO | Back to top

Comments on this post: Retrieving Rules from an Exchange Account in Outlook using VSTO

# Rules for defer delivery message
Requesting Gravatar...
Could you help me
I need to create a rule in outlook for defer a delivery message
The code is like that :
Set colRules = Application.Session.DefaultStore.GetRules()
‘Create the rule by adding a SendRule to Rules collection
Set oRule = colRules.Create(“Envoi différé”, olRuleSend)
Set oDeferRuleAction = oRule.Actions(OlRuleActionType.olRuleActionDefer)
With oDeferRuleAction
.enabled = True
then the first action is activate “delete category” but not defer delivery and I can’t set a number of minutes

End With
some thing is missing I don’t know

tank’s a lot for your help
Left by Lamboeuf on Jan 12, 2012 6:07 PM

Your comment:
 (will show your gravatar)

Copyright © Pranav | Powered by: