derwowusste
Goto Top

Syntaxfrage zu Skript zur Outlookregelerstellung

Moin.

Habe folgendes VB-Skript:
Const RULE_NAME = "Move SPAM to SPAM Folder"  
Const olRuleReceive = 0
Const olFolderInbox = 6
Dim olkApp, olkSes, olkCol, olkRul, olkCD1, olkCD2, olkMRA, oCurrentRule, blnFound
Set olkApp = CreateObject("Outlook.Application")  
Set olkSes = olkApp.GetNamespace("MAPI")  
olkSes.Logon olkApp.DefaultProfileName
Set olkCol = olkSes.DefaultStore.GetRules()

' Look to see if Rule Exists  
blnFound = False
For Each oCurrentRule In olkCol 
  If oCurrentRule.Name = RULE_NAME Then blnFound = True
Next

' If the Rule has not been found, add it  
If not blnFound Then
	Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
	Set olkCD1 = olkRul.Conditions.Subject
	With olkCD1
	    .Enabled = True
	    .Text = Array("***SPAM***")  
	End With
	Set olkMRA = olkRul.Actions.MoveToFolder
	With olkMRA
	    set .Folder = olkSes.GetDefaultFolder(olFolderInbox).Folders("SPAM")  
	    .Enabled = True
	End With
	olkCol.Save False
End If

olkSes.Logoff	
olkApp.Quit
Set olkMRA = Nothing
Set olkCD2 = Nothing
Set olkCD1 = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing

WScript.Quit
Dieses soll nun erweitert werden um eine Ausnahme, siehe Bild:
rule
Habt Ihr die Syntax parat für diese Ausnahme?

Content-Key: 377126

Url: https://administrator.de/contentid/377126

Printed on: April 18, 2024 at 17:04 o'clock

Member: Friemler
Solution Friemler Jun 15, 2018 at 07:56:52 (UTC)
Goto Top
Moin

Nur geraten:
Set olkEx1 = olkRul.Exceptions.Subject

With olkEx1
  .Enabled = True
  .Text    = Array("FW: ***SPAM***")  
End With


Siehe:

Rule Object
Rule.Exceptions Property
RuleConditions Object
RuleConditions.Subject Property
TextRuleCondition Object
TextRuleCondition.Text Property
Member: emeriks
Solution emeriks Jun 15, 2018 at 07:58:55 (UTC)
Goto Top
Member: DerWoWusste
DerWoWusste Jun 15, 2018 at 08:37:24 (UTC)
Goto Top
@Friemler: Perfekt!
Const RULE_NAME = "test"  
Const olRuleReceive = 0
Const olFolderInbox = 6
Dim olkApp, olkSes, olkCol, olkRul, olkCD1, olkCD2, olkMRA, oCurrentRule, blnFound
Set olkApp = CreateObject("Outlook.Application")  
Set olkSes = olkApp.GetNamespace("MAPI")  
olkSes.Logon olkApp.DefaultProfileName
Set olkCol = olkSes.DefaultStore.GetRules()

' Look to see if Rule Exists  
blnFound = False
For Each oCurrentRule In olkCol 
  If oCurrentRule.Name = RULE_NAME Then blnFound = True
Next

' If the Rule has not been found, add it  
If not blnFound Then
	Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
	Set olkCD1 = olkRul.Conditions.Subject
	With olkCD1
	    .Enabled = True
	    .Text = Array("***SPAM***")  
	End With
	Set olkEx1 = olkRul.Exceptions.Subject

    With olkEx1
      .Enabled = True
      .Text    = Array("FW: ***SPAM***")  
    End With
	Set olkMRA = olkRul.Actions.MoveToFolder
	With olkMRA
	    set .Folder = olkSes.GetDefaultFolder(olFolderInbox).Folders("SPAM")  
	    .Enabled = True
	End With
	olkCol.Save False
End If

olkSes.Logoff	
olkApp.Quit
Set olkMRA = Nothing
Set olkCD2 = Nothing
Set olkCD1 = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing

WScript.Quit

Danke Euch beiden für die Links. Ja, das könnte man sich auch selber zusammenfriemeln, aber es hat sich ja ein Friemler gefunden face-wink

Vielen Dank!
Member: DerWoWusste
DerWoWusste Jun 15, 2018 updated at 08:54:52 (UTC)
Goto Top
Ich war zu voreilig.

Wie müsste der Code sein, damit die bisherige Regel mit dem selben Namen durch die neue ersetzt wird?
Member: emeriks
emeriks Jun 15, 2018 updated at 09:04:07 (UTC)
Goto Top
ungefähr so

set olkRul = nothing

' Look to see if Rule Exists  
For Each oCurrentRule In olkCol 
  If oCurrentRule.Name = RULE_NAME Then Set olkRul  = oCurrentRule 
Next

If olkRul  is Nothing then
  Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)
end if

'kein Else !  

If not olkRul  is Nothing  Then
	Set olkCD1 = olkRul.Conditions.Subject
	With olkCD1
	    .Enabled = True
	    .Text = Array("***SPAM***")  
	End With
	Set olkEx1 = olkRul.Exceptions.Subject

    With olkEx1
      .Enabled = True
      .Text    = Array("FW: ***SPAM***")  
    End With
	Set olkMRA = olkRul.Actions.MoveToFolder
	With olkMRA
	    set .Folder = olkSes.GetDefaultFolder(olFolderInbox).Folders("SPAM")  
	    .Enabled = True
	End With
	olkCol.Save False
End If
Member: DerWoWusste
DerWoWusste Jun 15, 2018 at 10:38:55 (UTC)
Goto Top
Sehr schön, läuft. Nochmals Danke.
Member: DerWoWusste
DerWoWusste Jul 17, 2018 updated at 08:29:36 (UTC)
Goto Top
Hi emeriks.

Hast Du für mich vbs-Loser noch einen Tipp, wie die Syntax wäre, wenn man zwei Ausdrücke ausschließen wollte?
Also Ausnahme 1 wie gehabt: "FW: ***SPAM***"  
Und Ausnahme 2: "RE: ***SPAM***"  
?
Member: emeriks
Solution emeriks Jul 17, 2018 updated at 08:38:36 (UTC)
Goto Top
Hi DWW,
Zeile 24 (meine Antwort: 15.06.2018, aktualisiert um 11:04 Uhr )
.Text    = Array("FW: ***SPAM***" , "RE: ***SPAM***")   

Das kannst Du beliebig erweitern.
Member: DerWoWusste
DerWoWusste Jul 17, 2018 at 08:50:01 (UTC)
Goto Top
Danke nochmals face-smile