automatically forward from a specific email address

T

teamakg

here's a quick summary of what i'm trying to do. if an email arrives
from a certain address after 5pm and before 7am it is automatically
forwarded to another email. i found the following code on microsoft's
site but i can't seem to modify it so that it'll do what i need.
MailItem has something called SenderEmailAddress but i can't figure out
how to use it. tia.


=================================================================

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 7:00 A.M. and 5:00 P.M.
If Time() < #7: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 "(e-mail address removed)"

' Send it
myForward.Send

End If

End If

End Sub
 
M

Michael Bauer

Am 4 Nov 2005 09:48:57 -0800 schrieb (e-mail address removed):
If Time() < #7:00:00 AM# Or Time() > #5:00:00 PM# Then

Use the AND operator instead of OR.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top