• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

Outlook 2007 rules import format or syntaxis

Hi,

I have Outlook 2007 we certain rules. I would like to delete them all and start from scratch. The idea is that e-mails sent or received with a certain domain be movedo to a certain folder or e-mails to or from a certain e-mail address be sent to a subfolder.

I would like to know if this is possible to create the rules using an editor (text or similar) to create the rules. If so I need the syntaxis to use or the rule export format that then could be imported into Outlook. Also how to import those rules into Outlook.

TIA

0
moose25
Asked:
moose25
  • 4
  • 2
2 Solutions
 
David LeeCommented:
Hi, moose25.

"I would like to know if this is possible to create the rules using an editor (text or similar) to create the rules."
No, that's not possible.  You have two options.  One, create the rules using the Outlook GUI.  Two, write a script that creates the rules.  Why would you want to create the rules using a text editor?  How would that be simpler or better than creating them using Outlook's rules wizard?
0
 
moose25Author Commented:
Wizard is slow. also when sending an e-mail I would like to have it moved to a folder not to have a copy of it in it. This way porting rules would also be simpler.

Perhaps a script woul do it. Any examples in how to do it?
Basically the rules would be
Incoming e-mails:
 a) any e-mail with sender =@domain_of_sender.whatever MOVE it to folder Domain_of_server or any other name we might consider
  b) any e-mail with sender name@whatever.whatever MOVE it to folder or subfolder "whatever" or any other name we might consider


Outgoing e-mails
   a) any e-mail sent to=@domain_of_sender.whatever MOVE it to folder Domain_of_server or any other name we might consider
   b) any e-mail sent to name@whatever.whatever MOVE it to folder or subfolder "whatever" or any other name we might consider


TIA

Regards


0
 
David LeeCommented:
"Wizard is slow"
Perhaps.  It's still probably faster than writing code to make a rule.  The code in the snippet is what's required to create the first of the four rules you mentioned.  

"I would like to have it moved to a folder not to have a copy of it in it"
Creating rules via scripting does not add to the list of actions you can take on a message.  They're the same.  The wizard doesn't offer the ability to move the item, so it cannot be done by creating the rule via scripting.

"This way porting rules would also be simpler"
True.

Continued in the next post.
Sub CreateRule1()
    Dim olkRules As Outlook.Rules, _
        olkRule As Outlook.Rule, _
        olkCondition As Outlook.AddressRuleCondition, _
        olkAction As Outlook.MoveOrCopyRuleAction
    Set olkRules = Outlook.Application.Session.DefaultStore.GetRules()
    Set olkRule = olkRules.Create("Rule 1", olRuleReceive)
    With olkRule
        'Create the condition'
        Set olkCondition = .Conditions.SenderAddress
        olkCondition.Address = Array("@domain_of_sender.whatever")
        olkCondition.Enabled = True
        'Create the action taken if the condition is true'
        Set olkAction = .Actions.MoveToFolder
        olkAction.Folder = OpenOutlookFolder("Personal Folders\Testing")
        olkAction.Enabled = True
    End With
    olkRules.Save
    Set olkAction = Nothing
    Set olkCondition = Nothing
    Set olkRule = Nothing
    Set olkRules = Nothing
End Sub

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
David LeeCommented:
Rules may not be the solution.  We can emulate the behavior of rules using code.  For example, the code in the snippet will handle both of the sending conditions.  You could add additional conditions by simply adding a new IF ... THEN and a new CASE statement.  There's is some supporting code I haven't included so you can make a direct comparison between the two approaches.  That support code is required for both.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim olkRecipient As Outlook.Recipient, intAction As Integer
    If Item.Class = olMail Then
        For Each olkRecipient In Item.Recipients
            If InStr(1, LCase(olkRecipient.Address), "@domain_of_sender.whatever") Then
                intAction = 1
                Exit For
            End If
            If InStr(1, LCase(olkRecipient.Address), "name@whatever.whatever") Then
                intAction = 2
                Exit For
            End If
        Next
        Select Case intAction
            Case 1  '<-- Match on domain name'
                Item.SaveSentMessageFolder = OpenOutlookFolder("Mailbox - Doe, John\Messages to domain_of_sender.whatever")
            Case 2  '<-- Match on addressee name'
                Item.SaveSentMessageFolder = OpenOutlookFolder("Mailbox - Doe, John\Messages to name@whatever.whatever")
        End Select
        Item.Save
    End If
End Sub

Open in new window

0
 
moose25Author Commented:
thanks
0
 
David LeeCommented:
You're welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now