I manage several mail accounts in my Outlook
and I want to check if there is any change happens in any of the mails folder (received a mail). Then check Folder name is "My Out Folder" then it should forward that mail to specified account i.e "ABC@gmail.com"
The following code only handle first Mail Account folders. I don't want to use several variables for every mail so I am looking for a way to create class module so that it can detect Change_events in all the emails. only trigger when the folder name is "My Out Folder". Following is in class "ThisOutlookSession":
Const FowardEmailAddress As String = "ABC@gmail.com"
Public WithEvents myOutFolder As Outlook.Folders
Private Sub Application_Startup()
Set MyNS = Application.GetNamespace("MAPI")
Set myOutFolder = MyNS.Folders(1).Folders
End Sub
Private Sub myOutFolder_FolderChange(ByVal Folder As Outlook.Folder)
Dim FowardItem As Outlook.MailItem
If Folder.Name = "My Out Folder" Then
Set FowardItem = Folder.Items.GetFirst
AutoForwardAllSentItems FowardItem, FowardEmailAddress
End If
End Sub
code of AutoForwardAllSentItems() is in module:
Sub AutoForwardAllSentItems(Item As Outlook.MailItem, FM$)
Dim strMsg As String
Dim myFwd As Outlook.MailItem
Set myFwd = Item.Forward
myFwd.Recipients.Add FM
myFwd.Send
'myFwd.Display
Set myFwd = Nothing
End Sub
I don't know what is best way to achieved the same results.