Outlook 2003: Script to add text to subject line

Scenario:

Presently, when BackupExec Success emails drop into the IT Dept mailbox, I move them over unread to my personal mailbox into a "Backups" folder.  Once all are in, I then manually edit the subject line to place my initials at the beginning, mark as read, and move back to the IT Dept mailbox into a specific folder.

Is there any way I can automate this process with a rule or script?  I had a quick look in Rules and Alerts and it doesn't look like there is any native capability to automate this...?
LVL 1
Stuart OramIT Technician - Project SitesAsked:
Who is Participating?
 
Chris BottomleyConnect With a Mentor Software Quality Lead EngineerCommented:
Ah-Ha, I am using 2007 so try this:

Chris
Sub EE_24351554(mai As mailitem)
Const olkSender As String = "backupexec@<companyname>.com"
Const olkSubject As String = "Backup Exec Alert: Job Success"
Dim olkMovetoFolder As Outlook.mapiFolder
 
    Set olkMovetoFolder = Application.Session.GetDefaultFolder(olFolderInbox).folders("Backups")
    If LCase(mai.SenderEmailAddress) = LCase(olkSender) And _
        Left(LCase(mai.subject), Len(olkSubject)) = LCase(olkSubject) Then
        mai.subject = "SO - " & mai.subject
        mai.UnRead = False
        mai.Save
        mai.Move olkMovetoFolder
    End If
 
End Sub

Open in new window

0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
If you can identify the email address or subject line that is consistent with identifying these emails then via a script they can be moved, and the subject line edited all in the same automatic action upon receipt without user interaction ... if that is what is wanted?

Chris
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Chris,
Indeed - all of the emails come in from backupexec@<companyname>.com
and carry "Backup Exec Alert: Job Success" as the start of the subject line.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
Chris BottomleySoftware Quality Lead EngineerCommented:
Sjoram:

To confirm you would like to do the activity as soon as the email is received? Assuming yes then ...

What is the destination folderpath ... put the cursor on the folder in the explorer then type this in the VBE immediate window(ctrl + G to display):

?application.ActiveExplorer.CurrentFolder.FolderPath

Chris
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Chris,
Not sure what you mean by the above?
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
>>> I move them over unread to my personal mailbox into a "Backups" folder.

Th elast post was to find the move to folder so that it can be coded into a script.  SInce the solution will be VBA based and I assumed a degree of familiarity.

In outlook put the cursor onto the backups folder.
In outlook press alt + F11 to open the VBE
In the VBE press ctrl + G to ensure the immediate window is displayed
in the immediate window of the VBE, (it has a title to simplify finding it) type the command:
?application.ActiveExplorer.CurrentFolder.FolderPath
and teh VBE will return a string ... copy that string here.

Chris
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Sorry - I thought it mught be a VB but wasn't 100% - No I haven't dealt much with VB, but each little thing is teaching me more!

\\Mailbox - Oram, Stuart\Inbox\Backups
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
In the VBE, (see above)
Insert Module, (default name will be something like module1)
In this module paste the snippet, (modify initials if required)

In outlook:

Select rules and alerts in the tools menu
New rule | check messages when they arrive | next
Next again and accept the warning that this will apply to all incoming emails
Select run a script
click the script prompt and navigate to EE_24351554

Finish up as necessary ... ensure this machine only is not selected and it should work!

Chris
Sub EE_24351554(mai As mailitem)
Const olkSender As String = "backupexec@<companyname>.com"
Const olkSubject As String = "Backup Exec Alert: Job Success"
Dim olkMovetoFolder As Outlook.Folder
 
    Set olkMovetoFolder = Application.Session.GetDefaultFolder(olFolderInbox).folders("Backups")
    If LCase(mai.SenderEmailAddress) = LCase(olkSender) And _
        Left(LCase(mai.subject), Len(olkSubject)) = LCase(olkSubject) Then
        mai.subject = "SO - " & mai.subject
        mai.UnRead = False
        mai.Save
        mai.Move olkMovetoFolder
    End If
 
End Sub

Open in new window

0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Chris,
Thanks for that, looks good, I'll give it a try.
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Doesn't seem to work - see attached for the code as I've got it in there & details of my mailbox structure
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Image doesn't seem to want to attach, will try from another PC later..
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Any update?
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Sorry for delay. IE refused to upload, Firefox seems to have uploaded OK....
backupscript.JPG
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Are you sure the change is in place as a rule?  I will post a modified sub to stop the sub if it it is being called and try again.

The code should stop if it is called and press F8 in turn to see which lines are executed looking for anything silly ... but my strongest suspicion is that the rule is not calling the sub

Chris
Sub EE_24351554(mai As mailitem)
Const olkSender As String = "backupexec@<companyname>.com"
Const olkSubject As String = "Backup Exec Alert: Job Success"
Dim olkMovetoFolder As Outlook.Folder
 
    stop
    Set olkMovetoFolder = Application.Session.GetDefaultFolder(olFolderInbox).folders("Backups")
    If LCase(mai.SenderEmailAddress) = LCase(olkSender) And _
        Left(LCase(mai.subject), Len(olkSubject)) = LCase(olkSubject) Then
        mai.subject = "SO - " & mai.subject
        mai.UnRead = False
        mai.Save
        mai.Move olkMovetoFolder
    End If
 
End Sub

Open in new window

0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
OK, an error has appeared this time, trying to run the original script...


backupscript2.jpg
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Now that is wierd!

To confirm, you have created a rule that calls the sub in outlook 2003 rules and alerts.
When the rule is triggered it stops on the line:
Dim olkMovetoFolder As Outlook.Folder
saying user defined type not identified?

Chris
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Worked a charm that time - must remember to change it back again when we roll-out Office 2007!!
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Glad to help but don't worry 2007 still recognises mapifolder it's just that i've got lazy!

Chris
0
 
Stuart OramIT Technician - Project SitesAuthor Commented:
Interesting that it worked first time on Terminal Server (server 2008, outlook 2003) but no longer works, but still works on my client machine - xp, outlook 2003.....

Script copied exactly to the terminal server and as i say worked the first time, not subsequently....

Very odd...
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.

All Courses

From novice to tech pro — start learning today.