Forward Outlook Emails to your Pager or to your Public Email Account

Last few weeks I was searching the ways of forwarding Outlook incoming emails to my mobile or to a public email account. After writing few code blocks and testing various SMTP related methodologies the best option I found so far is the Outlook Macro option.

Using Outlook Macro option you can write a custom VB code as the way you want and trigger it by using Outlook events such as when a new email received, send, etc. You can easily forward your Outlook emails to any number of public email addresses, your mobile Pager address in a totally customized way. You will receive the forwarded email to your public mail account or to your mobile as same way you send through the Outlook.

Here is the code I have written and try it with your own risk.

  1. MS Outlook 2007 > Tools > Macro > Visual Basic Editor
  2. Copy & paste below code
  3. Edit and provide your public email address within the code, Save and Run it.
  4. This will trigger when you receive a new email address and forward the content to given mail account

'This event trigger each time when a new email received to your Outlook

Private Sub Application_NewMail()

Dim sSubject As String

Dim sBody As String

Dim flag As String

' Open the default Inbox Folder.

Set objItemInbox = Application.GetNamespace("MAPI"). _

GetDefaultFolder(olFolderInbox).Items.GetLast

' Open the custom mail box folder that you have created.

Set objItemLA = Session.Application.GetNamespace("MAPI"). _

Folders("Personal Folders").Folders("LA Support").Items.GetLast

flag = 1

' If unread mail exist in your inbox, retrieve the 1st unread mail and assign details to the variables.

If objItemInbox.UnRead Then

sSubject = objItemInbox.Subject & " From: " & _

objItemInbox.SenderName

sBody = objItemInbox.Body

' If unread mail exist in your custom mail box, retrieve the 1st unread mail and assign details to the variables.

ElseIf objItemLA.UnRead Then

sSubject = objItemLA.Subject & " From: " & _

objItemLA.SenderName

sBody = objItemLA.Body

Else

flag = 0

End If

If flag = 1 Then

' Create a new outlook email Object using received email contents

Set objMailItem = Application.CreateItem(olMailItem)

With objMailItem

.Subject = sSubject

.Body = sBody

'Add your preferred public email account

.Recipients.Add "YourPublicEmail@gmail.com"

.Send

End With

Set objMailItem = Nothing

End If

End Sub

No comments:

Post a Comment