?
Solved

Outlook 2003: Script to add text to subject line

Posted on 2009-04-23
19
Medium Priority
?
784 Views
Last Modified: 2012-05-06
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...?
0
Comment
Question by:Stuart Oram
  • 10
  • 9
19 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24222417
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
 
LVL 1

Author Comment

by:Stuart Oram
ID: 24222580
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24222598
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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 1

Author Comment

by:Stuart Oram
ID: 24222765
Chris,
Not sure what you mean by the above?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24222791
>>> 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
 
LVL 1

Author Comment

by:Stuart Oram
ID: 24222948
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24223154
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
 
LVL 1

Author Comment

by:Stuart Oram
ID: 24223800
Chris,
Thanks for that, looks good, I'll give it a try.
0
 
LVL 1

Author Comment

by:Stuart Oram
ID: 24223881
Doesn't seem to work - see attached for the code as I've got it in there & details of my mailbox structure
0
 
LVL 1

Author Comment

by:Stuart Oram
ID: 24223892
Image doesn't seem to want to attach, will try from another PC later..
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24236416
Any update?
0
 
LVL 1

Author Comment

by:Stuart Oram
ID: 24240556
Sorry for delay. IE refused to upload, Firefox seems to have uploaded OK....
backupscript.JPG
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24241492
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
 
LVL 1

Author Comment

by:Stuart Oram
ID: 24241897
OK, an error has appeared this time, trying to run the original script...


backupscript2.jpg
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24248167
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
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 24248182
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
 
LVL 1

Author Closing Comment

by:Stuart Oram
ID: 31574119
Worked a charm that time - must remember to change it back again when we roll-out Office 2007!!
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 24254126
Glad to help but don't worry 2007 still recognises mapifolder it's just that i've got lazy!

Chris
0
 
LVL 1

Author Comment

by:Stuart Oram
ID: 24274818
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

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question