Macro for Outlook email forwarding

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?
InoAdminAsked:
Who is Participating?
 
David LeeConnect With a Mentor Commented:
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
 
David LeeCommented:
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
 
InoAdminAuthor Commented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
InoAdminAuthor Commented:
Thanks for your help and quick response, much appreciated
0
 
David LeeCommented:
You're welcome.  Glad I could help.
0
 
obi-wonCommented:
Does this require using an MS exchange server or can it work with a stand alone outlook 2007 using a pop3 account?
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.