Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating an Outlook rule in Session module (VBA - Outlook - 2002)

    I need to automate the task of setting up rules in outlook for all my (200) users. What I need to do is search the header of every new email coming in for a line of text. This is for some new spam software that we have. Is there a way to setup a rule exactly like in the rules wizard that says, "When message arrives with "some text" in the header of the message, send to a certain folder"?

    I have attempted to do this but cannot find the method or properties for referencing the header of new emails. If anyone has any samples of code or suggestions please let me know.

    Also I noticed that outlook rules has an import rule feature. If I can access this import feature from within code I could place the rwz file on the server and import it to each workstation. Is this possible??

    Thanks in advance.
    Don

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Creating an Outlook rule in Session module (VBA - Outlook - 2002)

    I can answer parts of your question, but I don't know the server side, so perhaps a Lounger with Exchange experience can help. It might also be wise to make a post in the Server Forum pointing to your post; there may be server-side solutions that work better for you..

    It's easy to write Outlook VBA code that addresses the MailItem.Subject at the client end. I'ts not nearly so easy in Outlook to distribute code to client end users, and, at least through OL 2002, Rules are not exposed in the Outlook Object Model; automatic importing of *.RWZ is beyond my knowledge; there may be a user script way to do this, or, <!mskb=251125>Microsoft Knowledge Base Article 251125<!/mskb> may be of interest.
    -John ... I float in liquid gardens
    UTC -7DS

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating an Outlook rule in Session module (VB

    Please note that, from 2002, Outlook started storing rules within the datastore and not within the RWZ file. Thus you would be looking at importing the Rules into the datastore. HTH
    Gre

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Creating an Outlook rule in Session module (VBA - Outlook - 2002)

    <P ID="edit" class=small>(Edited by jscher2000 on 10-Feb-04 14:58. Whoops)</P>I don't think you can access the Rules Wizard in code, but truth be told, I haven't really checked since Outlook 2000...

    As an example of a rule that looks in a message header, see the attached. I doubt you have any similarly named rule (Move X-Spam-Level: 5 or more), so it should be safe to import. (As a side note, to make this file I had to export the rules to backup.rwz, delete all the other rules in Outlook, then export this one to a different RWZ, then delete that rule, then import the backup.)

    Plan B: That file contains sensitive information about file locations, so I've supplied a screen shot instead.

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating an Outlook rule in Session module (VBA - Outlook - 2002)

    I have no problem creating the rule manually, but I'm trying to avoid having to rely on the 200 users to properly create the rule themselves. Do you know how to access the header text of all incoming email in vba code? By doing this, I would be able to avoid having the users create the rules. I could place it in Outlooks session module which would fire whenever a new message arrives.

    Thank you everyone for your replies!
    Don

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Creating an Outlook rule in Session module (VBA - Outlook - 2002)

    Unless it was added to the Outlook object model recently, or exists in the CDO object model, you might have to license the Redemption library (see http://www.dimastr.com/) to do this. Some sample code to access the message header using Redemption:

    <pre>Sub ShowHeaders()
    ' Requires Outlook Redemption from http://www.dimastr.com/redemption/ to
    ' access the headers
    Dim msg As Outlook.MailItem
    If Inspectors.Count > 0 Then
    ' Use the ActiveInspector, hopefully it's a mail message!
    Set msg = ActiveInspector.CurrentItem
    Else
    ' Use the message selected in the list, if any
    If ActiveExplorer.Selection.Count = 0 Then
    MsgBox "Please select a mail message and try again.", _
    vbCritical + vbOKOnly, "ShowHeaders Error"
    Exit Sub
    End If
    Set msg = ActiveExplorer.Selection.Item(1)
    End If
    ' Declare variables and constants
    Dim strHeaders As String
    Dim utils As Object ' for Redemption
    Const PrInternetHeaders = &H7D001E ' for Redemption
    ' Create objects
    ' Late binding - no Reference needed
    Set utils = CreateObject("Redemption.MAPIUtils")
    ' Use Redemption to retrieve the Internet Headers
    strHeaders = utils.HrGetOneProp(msg.MAPIOBJECT, PrInternetHeaders)
    ' Clean up Redemption objects; very important!!!
    utils.CleanUp
    If Not (utils Is Nothing) Then Set utils = Nothing
    ' Clean up other object references
    If Not (msg Is Nothing) Then Set msg = Nothing
    ' Display headers
    Debug.Print strHeaders
    If Len(strHeaders) > 1024 Then
    MsgBox strHeaders, vbInformation, "First 1024 Bytes of Message Headers"
    Else
    MsgBox strHeaders, vbInformation, "Message Headers"
    End If
    End Sub</pre>

    Hope this helps.

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating an Outlook rule in Session module (VBA - Outlook - 2002)

    Yes this does give me some ideas. Thanks for the example!

    Don

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •