Solved

Macro for Outlook email forwarding

Posted on 2008-10-13
6
901 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

752 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