How to: Create an Outlook rule to modify the subject line or body of an incoming email message


Instructions

NOTE: This will create a client-side rule that will only run while Outlook is open and connected to the Exchange Server.

1) Go to the Developer tab in Outlook.

TIP: If you do not see the Developer tab, right-click your ribbon and choose Customize Ribbon. Then, in the right-hand pane, check the box next to "Developer" and click OK.

2) Click Visual Basic.

3) In the left-hand pane, expand "Project1". Then, expand "Microsoft Outlook Objects" and click ThisOutlookSession.

4) Paste the following code into the right-hand window:

Sub MyScriptName(Item As Outlook.MailItem)

Dim objMsg As MailItem

Set objMsg = Application.CreateItem(olMailItem)

Dim BodyAppend As String

Dim SubjectAppend As String

Dim Recipients As String

BodyAppend = "a_body_to_append" 'This text will be appended to the body.

SubjectAppend = "a_subject_to_append" 'This text will be appended to the subject.

ToEmail = "someemailaddress@somedomain.com" 'Email address to which to redirect the message.

objMsg.Body = BodyAppend + vbCrLf + Item.Body

objMsg.Subject = Item.Subject + SubjectAppend

objMsg.Recipients.Add ToEmail

objMsg.Send

End Sub

Be sure to change the following variables in the script above:

  • MyScriptName - Any name you would like to use for the script. You will need this in StepĀ 6.
  • a_body_to_append - The text you want to append to the body. If you do not wish to append anything to the body, delete everything between the quotation marks.
  • a_subject_to_append - The text you want to append to the subject line. If you do not wish to append anything to the subject line, delete everything between the quotation marks.
  • someemailaddress@somedomain.com - An email address where you want to redirect the message. If you do not wish to redirect the email message, delete everything between the quotation marks.

TIP: To append multiple lines to the body, create multiple variables for each line. You will need a "Dim" line for each one, plus a line defining the string for that variable. Finally, the line beginning with "objMsg.Body" should include each of your defined variables separated by as many carriage returns (vbCrLf) as you need.

5) Click the save icon on your toolbar and close the Visual Basic window.

6) Set up a new rule in Outlook with the settings you want. For actions, check the box next to "run a script". Then, choose the script you just created.

7) Save the rule.


OUTCOME

Incoming email messages will be modified according to your script.