tags:

views:

1448

answers:

3

Basically, we have a rule setup to run a script when a code word is detected in the body of an incoming message. The script will append the current subject header with a word in front. For example, Before: "Test Message", After: "Dept - Test Message". Any ideas?

A: 

Not tested:

mailItem.Subject = "Dept - " & mailItem.Subject
mailItem.Save
Matt
+2  A: 

Or if you need an entire script:

Do the Run a script with the MailItem as the parameter.

Sub RewriteSubject(MyMail As MailItem)

    Dim mailId As String
    Dim outlookNS As Outlook.NameSpace
    Dim myMailItem As Outlook.MailItem

    mailId = MyMail.EntryID
    Set outlookNS = Application.GetNamespace("MAPI")
    Set myMailItem = outlookNS .GetItemFromID(mailId )

    ' Do any detection here

    mailItem.Subject = "Dept - " & mailItem.Subject
    myMailItem .Save

    Set mailItem = Nothing
    Set outlookNS = Nothing

End Sub
Matt
A: 
Sub AppendSubject(MyMail As MailItem)
    Dim strID As String
    Dim mailNS As Outlook.NameSpace
    Dim mailItem As Outlook.MailItem

    strID = MyMail.EntryID
    Set mailNS = Application.GetNamespace("MAPI")
    Set mailItem = mailNS.GetItemFromID(strID)
    mailItem.Subject = "Dept - " & mailItem.Subject
    mailItem.Save

    Set mailItem = Nothing
    Set mailNS = Nothing
End Sub

Are we missing anything? EDIT: Doh! You already answered our question with a full script... Thanks!