Solved

Macro for Outlook email forwarding

Posted on 2008-10-13
6
893 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

To stay competitive, modern businesses must adapt and stay innovative, and this is increasingly only possible by working with outside talent. Managers and executives have understood the power of outsourcing for quite some time, but traditional clien…
Companies keep a much closer eye on costs today, so changing to new Technology – Microsoft Office 365 is the smartest move to take.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now