Redemption - Rules for outlook

  • Thread starter Christopher Long
  • Start date
C

Christopher Long

Afternoon. Think i may have placed the last post in the wrong newsgroup so
please excuse the double post.

I have been using the redemption dll as of late in order to programatically
created a bunch of rules to filter emails (around 144 rules though this could
be more or less) based on items in a csv file.

All is good except for 1 little issue i just can't get myself past after a
few days of googling and trial and error. Below is a listing of code that
causes an error after around 49 rules with associated objects are created on
my system.

I've followed the posting and google results on the RPC limits and
marshaling to release objects and i'm sure thats the problem. I get a mixture
of errors mostly MAPI_E_NOT_ENOUGH_MEMORY and MAPI_E_CALLBACK (i think thats
it).

Works wonderfully for less than 49 objects but obviously would be better if
i could fix it. Can someone try the below code / offer some suggestions on
how to correctly release all explicit and implict objects and vars that might
be causing the problems? I'd be most appreciative. Was good seeing the light
at the end of the tunnel till i realised it was a train :/ at which point it
was too late.

Public Inbox As Redemption.RDOFolder
Public MainInbox As Redemption.RDOFolder

MainInbox = Store.GetDefaultFolder(DefaultInboxFolder.olFolderInbox)
Inbox = MainInbox.Folders(txtFolderName.Text)

Code:
Dim i As Integer
Dim strTestArray() As String

'temp test
Dim rule As Redemption.RDORule
Dim action As Redemption.RDORuleAction
Dim actions As Redemption.RDORuleActions
Dim subfolder As Redemption.RDOFolder
Dim strConditions As String

Debug.Listeners.Add(New
TextWriterTraceListener(System.AppDomain.CurrentDomain.BaseDirectory() &
"output.txt"))
Debug.AutoFlush = True

strConditions = "(SenderEmailAddress = '[email protected]') and (Body
like '%test%')"

subfolder = Inbox.Folders("Test")

For i = 1 To 100
ReDim strTestArray(2)
strTestArray(0) = "testrule" & i
strTestArray(1) = "Test"
strTestArray(2) = "Test"

' begin temp
rule = rules.Create(strTestArray(0))
'            subfolder = Inbox.Folders("Test")

actions = rule.Actions
action = actions.MoveToFolder
action.Folder = subfolder
action.Enabled = True

rule.ConditionsAsSQL = strConditions

rule.Enabled = True
rule.Save()


Marshal.ReleaseComObject(action)
Marshal.ReleaseComObject(actions)
Marshal.ReleaseComObject(rule)

GC.Collect()
' end temp

Debug.WriteLine(i)

Next i

MsgBox("test finished - " & i)
 
K

Ken Slovak - [MVP - Outlook]

See my answer in the other group.




Christopher Long said:
Afternoon. Think i may have placed the last post in the wrong newsgroup so
please excuse the double post.

I have been using the redemption dll as of late in order to
programatically
created a bunch of rules to filter emails (around 144 rules though this
could
be more or less) based on items in a csv file.

All is good except for 1 little issue i just can't get myself past after a
few days of googling and trial and error. Below is a listing of code that
causes an error after around 49 rules with associated objects are created
on
my system.

I've followed the posting and google results on the RPC limits and
marshaling to release objects and i'm sure thats the problem. I get a
mixture
of errors mostly MAPI_E_NOT_ENOUGH_MEMORY and MAPI_E_CALLBACK (i think
thats
it).

Works wonderfully for less than 49 objects but obviously would be better
if
i could fix it. Can someone try the below code / offer some suggestions on
how to correctly release all explicit and implict objects and vars that
might
be causing the problems? I'd be most appreciative. Was good seeing the
light
at the end of the tunnel till i realised it was a train :/ at which point
it
was too late.

Public Inbox As Redemption.RDOFolder
Public MainInbox As Redemption.RDOFolder

MainInbox =
Store.GetDefaultFolder(DefaultInboxFolder.olFolderInbox)
Inbox = MainInbox.Folders(txtFolderName.Text)

Code:
Dim i As Integer
Dim strTestArray() As String

'temp test
Dim rule As Redemption.RDORule
Dim action As Redemption.RDORuleAction
Dim actions As Redemption.RDORuleActions
Dim subfolder As Redemption.RDOFolder
Dim strConditions As String

Debug.Listeners.Add(New
TextWriterTraceListener(System.AppDomain.CurrentDomain.BaseDirectory() &
"output.txt"))
Debug.AutoFlush = True

strConditions = "(SenderEmailAddress = '[email protected]') and (Body
like '%test%')"

subfolder = Inbox.Folders("Test")

For i = 1 To 100
ReDim strTestArray(2)
strTestArray(0) = "testrule" & i
strTestArray(1) = "Test"
strTestArray(2) = "Test"

' begin temp
rule = rules.Create(strTestArray(0))
'            subfolder = Inbox.Folders("Test")

actions = rule.Actions
action = actions.MoveToFolder
action.Folder = subfolder
action.Enabled = True

rule.ConditionsAsSQL = strConditions

rule.Enabled = True
rule.Save()


Marshal.ReleaseComObject(action)
Marshal.ReleaseComObject(actions)
Marshal.ReleaseComObject(rule)

GC.Collect()
' end temp

Debug.WriteLine(i)

Next i

MsgBox("test finished - " & i)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top