Tuesday, March 8, 2011

Techie Post: How to forward your Outlook emails to another email address

Ok, so I realize most people reading this blog won't care about this topic, but I have a Blackberry cell phone and my company doesn't support syncing our Outlook work emails to Blackberry phones; however, sometimes it's very inconvenient when I am not at my computer but need to read work emails.

Here is one solution if all you need to do is forward emails at all times (if you only want emails forwarded during a time window, see below):



However, if the above solution doesn't work for you like it didn't for me as my company's email server blocks automatic forwarding, then you can use this solution below:

Below is a VBA script, a macro, that will forward emails received in your Outlook Inbox to an external email address. I needed this to forward work emails from Outlook to my Blackberry phone and it works.
To use it:

1. Start Outlook
2. Click Tools->Macro->Visual Basic Editor
3. If not already expanded, expand Microsoft Outlook Objects in the Project pane, then click on "ThisOutlookSession"
4. Copy the script below
5. Paste the script into the right-hand pane of the VB Editor
6. Edit the script making the changes as per the comments I included in the code
7. Click the diskette icon on the toolbar to save the changes
8. Close the VB Editor
9. Click Tools->Macro->Security
10. Set Security Level to Medium
11. Close Outlook
12. Start Outlook
13. A dialog-box will appear telling you the ThisOutlookSession contains macros and asking if you want to enable them. Say yes.
14. Test the macro
15. When the macro runs Outlook will present you with another dialog-box advising that a program is trying to access your mailbox and asking if you want to allow it to. Say yes.
16. If a message is received in the mailbox, and if the time is currently between the times you set, then the message will be forwarded to the designated email address. Otherwise, nothing will happen.
17. Once you've verified that the macro works as expected, then you need to sign the macro to avoid having Outlook security warn you each time the macro runs.
18.  Let me know if you need help.
'START CODE
Private WithEvents objInboxItems As Items

Private Sub Application_Startup()

Dim objNS As NameSpace

Set objNS = Application.GetNamespace("MAPI")

' instantiate Items collections for folders we want to monitor

Set objInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Set objNS = Nothing

End Sub



Private Sub Application_Quit()

' disassociate global objects declared WithEvents

Set objInboxItems = Nothing

End Sub



Private Sub objInboxItems_ItemAdd(ByVal Item As Object)

Dim olItems As Items, _

olItem As Object, _

olMailItem As MailItem, _

olAttachmentItem As Attachment, _

bolTimeMatch As Boolean

Set olItems = objInboxItems.Restrict("[Unread] = True")

For Each olItem In olItems

If olItem.Class = olMail Then

Set olMailItem = olItem

'Change the times on the next line to those you want to use

bolTimeMatch = (Time >= #4:00:00 PM#) And (Time <= #8:30:00 AM#)

If bolTimeMatch Then

Dim objMail As Outlook.MailItem

Set objItem = olMailItem

Set objMail = objItem.Forward

objMail.To = "joshjskelton@hotmail.com"

objMail.Send

Set objItem = Nothing

Set objMail = Nothing

End If

End If

Next

End Sub



Function IsNothing(Obj)

If TypeName(Obj) = "Nothing" Then

IsNothing = True

Else

IsNothing = False

End If

End Function
'END CODE

No comments:

Post a Comment