我一直在尝试创建一个规则,根据邮件主题将邮件移动到特定文件夹。我正在尝试使用c#来实现这一点,但我无法让它工作?
以下是代码:
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 PropVal 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