I have been trying to create a rule which will move mail to a specific folder based on the mail-subject. I am trying to use c# to achieve this, but I am not able to get it to work?
Here is the code:
Const ACTION_MOVE = 1
Const CdoPR_SENSITIVITY = &H360003
Const SENSITIVITY_COMPANY_CONFIDENTIAL = 3
const REL_EQ = 7
Const PR_Transport_Headers = &H0037001E
Set objRules = CreateObject("MSExchange.Rules")
Set objRule = CreateObject("MSExchange.Rule")
Set objPropVal = CreateObject("MSExchange.PropertyValue")
Set objAction = CreateObject("MSExchange.Action")
servername = "testserver.abc.com"
mailboxname = "test@abc.com"
Set objSession = CreateObject("MAPI.Session")
objSession.Logon "test@abc.com","test123",true,true,true,true,servername & vbLF & mailboxname
Set objInbox = objSession.Inbox
Set CdoInfoStore1 = objSession.GetInfoStore
Set CdoFolderRoot = CdoInfoStore1.rootFolder
Set CdoFolders1 = CdoFolderRoot.Folders
bFound = False
Set CdoFolder1 = CdoFolders1.GetFirst
Do While (Not bFound) And Not (CdoFolder1 Is Nothing)
If CdoFolder1.Name = "Private Inbox" Then
bFound = True
Else
Set CdoFolder1 = CdoFolders1.GetNext
End If
Loop
Set ActionFolder = CdoFolder1
' Create P开发者_JAVA百科ropVal for messages marked company confidential
Set importPropVal = CreateObject("MSExchange.PropertyValue")
importPropVal.Tag = PR_Transport_Headers
importPropVal.Value = "***Test***"
' Create property condition for when the message is marked company confidential
Set Cond_sens = CreateObject("MSExchange.PropertyCondition")
Cond_sens.PropertyTag = PR_Transport_Headers
Cond_sens.Operator = REL_EQ
Cond_sens.Value = importPropVal
objRules.folder = objInbox
objAction.ActionType = ACTION_MOVE
objAction.Arg = ActionFolder
objRule.Name = "Test Rule"
objRule.Condition = Cond_sens
objRule.Actions.Add , objAction
objRules.Add , objRule
objRules.Update
objSession.Logoff
精彩评论