Log in

View Full Version : Solved: Create a rule to forward messages from secondary (not default) email account



Johk Kara
11-05-2007, 01:46 PM
Hi,

I am working on a machine running Win Xp and Outlook 2003. Outlook has (2) two pop3 accounts setup i.e. email1@test.com and email2@test2.com and all email is saved in one pst. email1@test.com is set as the default account and as such executes a rule that forwards all incoming mail to an external account. What I would like is to have all mail forwarding to go through email2@test2.com and still have email1@test.com as my default account.

I have been doing some searching and came accross the code below, for forwarding I just don't have the knowhow to adjust it so as to make the forwarding procedure go through the secondary account.

////////

Public WithEvents myOlItems As Outlook.Items

Public Sub Application_Startup()
' Reference the items in the Inbox. Because myOlItems is declared
' "WithEvents" the ItemAdd event will fire below.
Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)
' If it's currently not between 9:00 A.M. and 5:00 P.M.
If Time() < #9:00:00 AM# Or Time() > #5:00:00 PM# Then
' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type
' of item it is.
If TypeName(Item) = "MailItem" Then
' Forward the item just received
Set myForward = Item.Forward
' Address the message
myForward.Recipients.Add "johk@example.com"
' Send it
myForward.Send
End If
End If
End Sub

/////

I would greatly appreciate any help on solving the above problem. Thanking you in advance for your adive and co-operation.

Regards

Johk

TonyJollans
11-08-2007, 04:32 AM
Outlook 2007 makes this much easier :)

In Outlook 2003 you have to use the command bars...
For Each Account In Item.GetInspector.CommandBars.FindControl(Id:=31224).Controls
If UCase(Split(Account.Caption, , 2)(1)) = "NAME OF YOUR ACCOUNT NUMBER 2" Then Account.Execute
Next

Johk Kara
11-09-2007, 08:54 AM
Thanks for your prompt reply, I'll try it out and see how it goes.

Thanks again

Johk