Solved

Macro for Outlook email forwarding

Posted on 2008-10-13
6
900 Views
Last Modified: 2010-04-21
I have a user that needs an automatiion system for a mailbox.  If an email is sent to this mailbox it should forward the email to 1 of 4 users in the company and preferably  cc the manager as well.   eg:  I have users A,B,C,D when an email is sent to the mailbox it must deliver to user A, the next time it must deliver to user B etc... sort of a round robin delivery system?
0
Comment
Question by:InoAdmin
  • 3
  • 2
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 22709802
Hi, InoAdmin.

The code below implements what you described.  Follow these instructions to use it.

1.  Start Outlook
2.  Click Tools->Macro->Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on Module1
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comments wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools->Macro->Security
9.  Set the Security Level to Medium
10. Close Outlook
11. Start Outlook
12. Create a rule that fires for the messages you want to forward
13. Set the rule's action to "run a script" and select this script as the one to run

The script uses a note to keep track of the next user to send to.  The script creates the note if it does not exist.  Deleting the note will simply start the round robin process over at user 1.

Sub RoundRobin(Item As Outlook.MailItem)
    Dim olkForward As Outlook.MailItem, olkNote As Outlook.NoteItem, strBody As String, intIndex As Integer
    On Error Resume Next
    Set olkNote = Session.GetDefaultFolder(olFolderNotes).Items.Find("[Subject]='RoundRobin'")
    If TypeName(olkNote) <> "NoteItem" Then
        Set olkNote = Application.CreateItem(olNoteItem)
        olkNote.Body = "RoundRobin" & vbCr & 1
        olkNote.Save
    End If
    On Error GoTo 0
    strBody = Replace(olkNote.Body, "RoundRobin" & vbCr, "")
    intIndex = CInt(strBody)
    Set olkForward = Item.Forward
    Select Case intIndex
        Case 1
            'Change the email address on the following line'
            olkForward.Recipients.Add "user1@company.com"
        Case 2
            'Change the email address on the following line'
            olkForward.Recipients.Add "user2@company.com"
        Case 3
            'Change the email address on the following line'
            olkForward.Recipients.Add "user3@company.com"
        Case 4
            'Change the email address on the following line'
            olkForward.Recipients.Add "user4@company.com"
    End Select
    intIndex = intIndex + 1
    If intIndex > 4 Then
        intIndex = 1
    End If
    olkNote.Body = "RoundRobin" & vbCr & intIndex
    olkNote.Save
    Set olkNote = Nothing
    'Change the email address on the following line'
    olkForward.CC = "manager@company.com"
    olkForward.Recipients.ResolveAll
    olkForward.Display
    Set olkForward = Nothing
End Sub

Open in new window

0
 

Author Comment

by:InoAdmin
ID: 22710118
I gave this a try but it needs a bit of fine tuning.  When an email is sent to the mailbox the new message window opens with the correct recipients displayed in the TO and CC fields however it does not send the message, it just sits in the new message window?  Is there also a way to implement this without having to have the mailbox open in Outlook all the time?
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 22710159
Sorry, forgot to change one line from when I was testing.  Change the word Display to Send on line #38.

No, there's no way to implement this without having the mailbox open all the time.  That would require an event-sink running on the Exchange server.  Event-sinks are like macros that run at the server.  However, they are more difficult to write and poorly written or buggy event-sink could bring the whole server down.
0
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 

Author Closing Comment

by:InoAdmin
ID: 31505787
Thanks for your help and quick response, much appreciated
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22710249
You're welcome.  Glad I could help.
0
 

Expert Comment

by:obi-won
ID: 23399945
Does this require using an MS exchange server or can it work with a stand alone outlook 2007 using a pop3 account?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Lately there has been a variety of news related to U.S. employment.  Stories about worker productivity, automobile and airline unions, low employment and foreign laborers have frequented the news.  Each story has good and bad attributes we might arg…
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

828 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