New Mail Notification for an Additional Mailbox


This morning I responded to a tweet from Tom Blackman (@itimlalake) asking how to set up a new mail notification for an additional mailbox in Outlook 2007. An additional mailbox in this context is a second mailbox on an Exchange server. Unfortunately, until 2010 Outlook did not support multiple mailboxes. While you could open and view additional mailboxes Outlook did not treat them as it does the primary mailbox. As a result things like new message notification and rules aren’t available for the additional mailboxes.

Fortunately, there is a workaround. It doesn’t look or behave the same as the built-in notification, but it is functional. The solution is to use a bit of scripting to monitor the additional mailbox’s inbox, watch for new items, and display a pop-up dialog-box when it detects one. The dialog-box is a standard Windows’ dialog, not the slick-looking notification that Outlook uses. The dialog doesn’t fade in and out, nor does it offer the ability to open or delete the message as Outlook’s notification dialog does. It will steal focus and you have to click a button to make it go away. While it’s not the best solution, it is a functional solution. Hopefully it will help Tom keep track of messages arriving in the additional mailbox.

The code for this comes in three parts.

Part 1.

Follow these instructions to add this code to Outlook.

  1. Start Outlook
  2. Click Tools > Macro > Visual Basic Editor
  3. If not already expanded, expand Microsoft Office Outlook Objects
  4. If not already expanded, expand Modules
  5. Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
  6. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  7. Edit the code as needed. I included comments wherever something needs to or can change
  8. Click the diskette icon on the toolbar to save the changes
  9. Close the VB Editor
'On the next line change the file name and path of the sound you want to play.'
Public Const SOUND_TO_PLAY = "C:\Windows\Media\Notify.wav"
Public Const SND_ASYNC = &H1

Public Declare Function sndPlaySound _
    Lib "winmm.dll" Alias "sndPlaySoundA" _ 
        (ByVal lpszSoundName As String, _
        ByVal uFlags As Long) _
    As Long 

Public Declare Function MessageBox _
    Lib "User32" Alias "MessageBoxA" _
        (ByVal hWnd As Long, _
        ByVal lpText As String, _
        ByVal lpCaption As String, _
        ByVal wType As Long) _
    As Long

Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
    ' Purpose: Opens an Outlook folder from a folder path.'
    ' Written: 4/24/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: All versions'
    Dim arrFolders As Variant, _
        varFolder As Variant, _
        bolBeyondRoot As Boolean
    On Error Resume Next
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        Do While Left(strFolderPath, 1) = "\"
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        Loop
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            Select Case bolBeyondRoot
                Case False
                    Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
                    bolBeyondRoot = True
                Case True
                    Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
            End Select
            If Err.Number <> 0 Then
                Set OpenOutlookFolder = Nothing
                Exit For
            End If
        Next
    End If
    On Error GoTo 0
End Function

Part 2.

Follow these instructions to add this code to Outlook.

  1. If not already expanded, expand Microsoft Office Outlook Objects
  2. Right-click on Class Modules, select Insert > Class Module
  3. In the Properties panel click on Name and enter FolderMonitor
  4. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  5. Edit the code as needed. I included comments wherever something needs to or can change
  6. Click the diskette icon on the toolbar to save the changes
Private WithEvents olkItems As Outlook.Items

Private Sub Class_Terminate()
    Set olkItems = Nothing
End Sub

Public Sub FolderToWatch(objFolder As Outlook.Folder)
    Set olkItems = objFolder.Items
End Sub

Private Sub olkItems_ItemAdd(ByVal Item As Object)
    Dim lngHandle As Long, lngReturn As Long
    sndPlaySound SOUND_TO_PLAY, SND_ASYNC
    MessageBox &O0, "New message arrived.", olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal 
End Sub 

Part 3.

Follow these instructions to add this code to Outlook.

  1. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  2. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  3. Edit the code as needed. I included comment lines wherever something needs to or can change
  4. Click the diskette icon on the toolbar to save the changes
  5. Close the VB Editor
  6. Click Tools > Trust Center
  7. Click Macro Security
  8. Set Macro Security to “Warnings for all macros”
  9. Click OK
  10. Close Outlook
  11. Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.
Dim objFM1 As FolderMonitor

Private Sub Application_Quit()
    Set objFM1 = Nothing
End Sub

Private Sub Application_Startup()
    Set objFM1 = New FolderMonitor
    'Edit the folder path on the next line as needed.'
    objFM1.FolderToWatch OpenOutlookFolder("Mailbox - TechnicLee\Inbox") 
End Sub 

Revisions.

  • Revision 1

This revision is for Ashok who asked for the ability to have different messages for different mailboxes (i.e. to have different text in the notification based on the mailbox being monitored) and to display the sender’s name in the notification. I added a third new feature, which is the ability to set different sounds for different mailboxes. Adding these features entailed adding three properties to the FolderMonitor class. Those properties are Message (used to set the message shown in the notification dialog-box), Sound (used to set the sound that will be played), and ShowSender (used to control whether the message sender is shown). All three settings are optional and use a default value if you opt not to use them. This makes the code more flexible, satisfying Ashok’s request without changing the code for those of you who don’t want the features that Ashok does.

To implement this revision, replace the code in the respective parts with this code, then close and restart Outlook. Refer to the instructions in the original post for details on how to add the code for each part.

Part 2.

Private WithEvents olkItems As Outlook.Items 
Private strMessage As String 
Private strSound As String 
Private bolShowSender As Boolean

Private Sub Class_Initialize()
    'On the next three lines edit the default values as desired.'
    strMessage = "New message arrived."
    strSound = "C:\Windows\Media\Notify.wav"
    bolShowSender = False
End Sub

Private Sub Class_Terminate()
    Set olkItems = Nothing
End Sub

Private Sub olkItems_ItemAdd(ByVal Item As Object)
    Dim lngHandle As Long, lngReturn As Long
    sndPlaySound strSound, SND_ASYNC
    If bolShowSender Then
        MessageBox &O0, strMessage & vbCrLf & "Sender: " & Item.SenderName, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
    Else
        MessageBox &O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
    End If
End Sub

Public Sub FolderToWatch(objFolder As Outlook.Folder)
    Set olkItems = objFolder.Items
End Sub

Public Property Let Message(ByVal strValue As String)
    strMessage = strValue
End Property

Public Property Let ShowSender(ByVal bolValue As Boolean)
    bolShowSender = bolValue
End Property

Public Property Let Sound(ByVal strValue As String)
    strSound = strValue
End Property

Part 3.

Dim objFM1 As FolderMonitor

Private Sub Application_Quit()
    Set objFM1 = Nothing
End Sub

Private Sub Application_Startup()
    Set objFM1 = New FolderMonitor
    With objFM1
        'The next line is optional. Delete it to use the default message. To set a message enter the text you want shown.'
        .Message = "New message in ..."
        'The next line is optional. Delete it or set the value to False if you do not want the sender shown.'
        .ShowSender = True
        'The next line is optional. Delete it to use the default sound. To set a sound edit name/path of the sound to play.'
        .Sound = "C:\Windows\Media\Notify.wav"
        'The next line is not optional.  Edit the folder path on the next line as needed.'
        .FolderToWatch OpenOutlookFolder("Mailbox - TechnicLee\Inbox")
    End With
End Sub
  • Revision 2

I created this revision for Jarratt. Jarratt wants to be able to monitor multiple folders, but for one of those folders he only wants a notification if the message came from a certain domain (e.g. gmail.com). This code builds on Revision 1 by adding that filtering capability.

To implement this revision, replace the code in the respective parts with this code, then close and restart Outlook. Refer to the instructions in the original post for details on how to add the code for each part.

Part 2.

Private WithEvents olkItems As Outlook.Items
Private strMessage As String
Private strSound As String
Private bolShowSender As Boolean
Private colFilter As Collection

Private Sub Class_Initialize()
    'On the next three lines edit the default values as desired.'
    strMessage = "New message arrived."
    strSound = "C:\Windows\Media\Notify.wav"
    bolShowSender = False
    Set colFilter = New Collection
End Sub

Private Sub Class_Terminate()
    Set olkItems = Nothing
End Sub

Private Sub olkItems_ItemAdd(ByVal Item As Object)
    Dim strSender As String, strDomain As String
    If Item.Class = olMail Then
        strSender = GetSMTPAddress(Item, GetOutlookVersion())
        On Error Resume Next
        strDomain = colFilter.Item(Mid(strSender, InStr(1, strSender, "@") + 1))
        On Error GoTo 0
        If (strDomain <> "") Or (colFilter.Count = 0) Then
            sndPlaySound strSound, SND_ASYNC
            If bolShowSender Then
                MessageBox &O0, strMessage & vbCrLf & "Sender: " & Item.SenderName, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
            Else
                MessageBox &O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
            End If
        End If
    End If
End Sub

Private Function GetSMTPAddress(Item As Outlook.MailItem, intOutlookVersion As Integer) As String
    Dim olkSnd As Outlook.AddressEntry, olkEnt As Object
    On Error Resume Next
    Select Case intOutlookVersion
        Case Is < 14
            If Item.SenderEmailType = "EX" Then
                GetSMTPAddress = SMTP2007(Item)
            Else
                GetSMTPAddress = Item.SenderEmailAddress
            End If
        Case Else
            Set olkSnd = Item.Sender
            If olkSnd.AddressEntryUserType = olExchangeUserAddressEntry Then
                Set olkEnt = olkSnd.GetExchangeUser
                GetSMTPAddress = olkEnt.PrimarySmtpAddress
            Else
                GetSMTPAddress = Item.SenderEmailAddress
            End If
    End Select
    On Error GoTo 0
    Set olkPrp = Nothing
    Set olkSnd = Nothing
    Set olkEnt = Nothing
End Function

Private Function GetOutlookVersion() As Integer
    Dim arrVer As Variant
    arrVer = Split(Outlook.Version, ".")
    GetOutlookVersion = arrVer(0)
End Function

Private Function SMTP2007(olkMsg As Outlook.MailItem) As String
    Dim olkPA As Outlook.PropertyAccessor
    On Error Resume Next
    Set olkPA = olkMsg.PropertyAccessor
    SMTP2007 = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x5D01001E")
    On Error GoTo 0
    Set olkPA = Nothing
End Function

Public Sub FolderToWatch(objFolder As Outlook.Folder)
    Set olkItems = objFolder.Items
End Sub

Public Property Let Filter(ByVal strValue As String)
    On Error Resume Next
    If colFilter.Item(strValue) = "" Then
        colFilter.Add strValue, strValue
    End If
    On Error GoTo 0
End Property

Public Property Let Message(ByVal strValue As String)
    strMessage = strValue
End Property

Public Property Let ShowSender(ByVal bolValue As Boolean)
    bolShowSender = bolValue
End Property

Public Property Let Sound(ByVal strValue As String)
    strSound = strValue
End Property

Part 3.

Dim objFM1 As FolderMonitor

Private Sub Application_Quit()
    Set objFM1 = Nothing
End Sub

Private Sub Application_Startup()
    Set objFM1 = New FolderMonitor
    With objFM1
        'The next line is optional and may be repeated as many times as necessary.  Enter an email domain name without the @ sign.  This will restrict notifications to just those message from that domain.
        .Filter = "gmail.com"
        'The next line is optional. Delete it to use the default message. To set a message enter the text you want shown.'
        .Message = "New message in ..."
        'The next line is optional. Delete it or set the value to False if you do not want the sender shown.'
        .ShowSender = True
        'The next line is optional. Delete it to use the default sound. To set a sound edit name/path of the sound to play.'
        .Sound = "C:\Windows\Media\Notify.wav"
        'The next line is not optional.  Edit the folder path on the next line as needed.'
        . FolderToWatch OpenOutlookFolder("Mailbox - TechnicLee\Inbox")
    End With
End Sub
  • Revision 3

I created this revision for David who asked for a knock-off that adds the ability to save message attachments to a specific folder. I implemented this new capability as an option David can activate on a per-mailbox basis. I also added the ability to display the message subject, sender’s name, or both in the notification dialog.

Part 1.

Follow these instructions to add this code to Outlook.

  1. Start Outlook
  2. Click Tools > Macro > Visual Basic Editor
  3. If not already expanded, expand Microsoft Office Outlook Objects
  4. If not already expanded, expand Modules
  5. Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
  6. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  7. Edit the code as needed. I included comments wherever something needs to or can change
  8. Click the diskette icon on the toolbar to save the changes
  9. Close the VB Editor
'On the next line change the file name and path of the sound you want to play.'
Public Const SOUND_TO_PLAY = "C:\Windows\Media\Notify.wav"
Public Const SND_ASYNC = &H1

Public Declare Function sndPlaySound _
    Lib "winmm.dll" Alias "sndPlaySoundA" _ 
        (ByVal lpszSoundName As String, _
        ByVal uFlags As Long) _
    As Long 

Public Declare Function MessageBox _
    Lib "User32" Alias "MessageBoxA" _
        (ByVal hWnd As Long, _
        ByVal lpText As String, _
        ByVal lpCaption As String, _
        ByVal wType As Long) _
    As Long

Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
    ' Purpose: Opens an Outlook folder from a folder path.'
    ' Written: 4/24/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: All versions'
    Dim arrFolders As Variant, _
        varFolder As Variant, _
        bolBeyondRoot As Boolean
    On Error Resume Next
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        Do While Left(strFolderPath, 1) = "\"
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        Loop
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            Select Case bolBeyondRoot
                Case False
                    Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
                    bolBeyondRoot = True
                Case True
                    Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
            End Select
            If Err.Number <> 0 Then
                Set OpenOutlookFolder = Nothing
                Exit For
            End If
        Next
    End If
    On Error GoTo 0
End Function

Part 2.

Private WithEvents olkItems As Outlook.Items
Private strMessage As String
Private strSaveToFolder As String
Private strSound As String
Private bolShowSender As Boolean
Private bolShowSubject As Boolean
Private colFilter As Collection

Private Sub Class_Initialize()
    'On the next three lines edit the default values as desired.'
    strMessage = "New message arrived."
    strSaveToFolder = ""
    strSound = "C:\Windows\Media\Notify.wav"
    bolShowSender = False
    bolShowSubject = False
    Set colFilter = New Collection
End Sub

Private Sub Class_Terminate()
    Set olkItems = Nothing
End Sub

Private Sub olkItems_ItemAdd(ByVal Item As Object)
    Dim strSender As String, strDomain As String, strAdditionalInfo As String, olkAttachment As Outlook.Attachment
    If Item.Class = olMail Then
        strSender = GetSMTPAddress(Item, GetOutlookVersion())
        On Error Resume Next
        strDomain = colFilter.Item(Mid(strSender, InStr(1, strSender, "@") + 1))
        On Error GoTo 0
        If (strDomain <> "") Or (colFilter.Count = 0) Then
            sndPlaySound strSound, SND_ASYNC
            If bolShowSender Then
                strAdditionalInfo = "Sender: " & Item.SenderName
            End If
            If bolShowSubject Then
                If strAdditionalInfo = "" Then
                    strAdditionalInfo = "Subject: " & Item.Subject
                Else
                    strAdditionalInfo = strAdditionalInfo & vbCrLf & "Subject: " & Item.Subject
                End If
            End If
            If strSaveToFolder <> "" Then
                For Each olkAttachment In Item.Attachments
                    If Not IsHiddenAttachment(olkAttachment) Then
                        olkAttachment.SaveAsFile strSaveToFolder & Format(Now, "yyyy-mm-dd-hh-nn-ss") & " " & olkAttachment.FileName
                    End If
                Next
            End If
            If strAdditionalInfo = "" Then
                MessageBox &O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
            Else
                MessageBox &O0, strMessage & vbCrLf & strAdditionalInfo, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
            End If
        End If
    End If
End Sub

Private Function IsHiddenAttachment(olkAtt As Outlook.Attachment) As Boolean
    Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001E"
    Dim olkPA As Outlook.PropertyAccessor, varTemp As Variant
    On Error Resume Next
    Set olkPA = olkAtt.PropertyAccessor
    varTemp = olkPA.GetProperty(PR_ATTACH_CONTENT_ID)
    IsHiddenAttachment = (varTemp <> "")
    On Error GoTo 0
    Set olkPA = Nothing
End Function

Private Function GetSMTPAddress(Item As Outlook.MailItem, intOutlookVersion As Integer) As String
    Dim olkSnd As Outlook.AddressEntry, olkEnt As Object
    On Error Resume Next
    Select Case intOutlookVersion
        Case Is < 14
            If Item.SenderEmailType = "EX" Then
                GetSMTPAddress = SMTP2007(Item)
            Else
                GetSMTPAddress = Item.SenderEmailAddress
            End If
        Case Else
            Set olkSnd = Item.Sender
            If olkSnd.AddressEntryUserType = olExchangeUserAddressEntry Then
                Set olkEnt = olkSnd.GetExchangeUser
                GetSMTPAddress = olkEnt.PrimarySmtpAddress
            Else
                GetSMTPAddress = Item.SenderEmailAddress
            End If
    End Select
    On Error GoTo 0
    Set olkPrp = Nothing
    Set olkSnd = Nothing
    Set olkEnt = Nothing
End Function

Private Function GetOutlookVersion() As Integer
    Dim arrVer As Variant
    arrVer = Split(Outlook.Version, ".")
    GetOutlookVersion = arrVer(0)
End Function

Private Function SMTP2007(olkMsg As Outlook.MailItem) As String
    Dim olkPA As Outlook.PropertyAccessor
    On Error Resume Next
    Set olkPA = olkMsg.PropertyAccessor
    SMTP2007 = olkPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x5D01001E")
    On Error GoTo 0
    Set olkPA = Nothing
End Function

Public Sub FolderToWatch(objFolder As Outlook.Folder)
    Set olkItems = objFolder.Items
End Sub

Public Property Let Filter(ByVal strValue As String)
    On Error Resume Next
    If colFilter.Item(strValue) = "" Then
        colFilter.Add strValue, strValue
    End If
    On Error GoTo 0
End Property

Public Property Let Message(ByVal strValue As String)
    strMessage = strValue
End Property

Public Property Let SaveToFolder(ByVal strValue As String)
    If strValue <> "" Then
        strSaveToFolder = strValue & IIf(Right(strValue, 1) = "\", "", "\")
    End If
End Property

Public Property Let ShowSender(ByVal bolValue As Boolean)
    bolShowSender = bolValue
End Property

Public Property Let ShowSubject(ByVal bolValue As Boolean)
    bolShowSubject = bolValue
End Property

Public Property Let Sound(ByVal strValue As String)
    strSound = strValue
End Property

Part 3.

Dim objFM1 As FolderMonitor

Private Sub Application_Quit()
    Set objFM1 = Nothing
End Sub

Private Sub Application_Startup()
    Set objFM1 = New FolderMonitor
    With objFM1
        'The next line is optional and may be repeated as many times as necessary.  Enter an email domain name without the @ sign.  This will restrict notifications to just those message from that domain.
        .Filter = "gmail.com"
        'The next line is optional. Delete it to use the default message. To set a message enter the text you want shown.'
        .Message = "New message in ..."
        'The next line is optional.  Delete it if you do not want to save the message attachments.  If you include this parameter, then the attachments will be saved to the specified folder.
         .SaveToFolder = "C:\Users\David\Documents\"
        'The next line is optional. Delete it or set the value to False if you do not want the sender shown.'
        .ShowSender = True
        'The next line is optional. Delete it or set the value to False if you do not want the subject shown.'
        .ShowSubject = True
        'The next line is optional. Delete it to use the default sound. To set a sound edit name/path of the sound to play.'
        .Sound = "C:\Windows\Media\Notify.wav"
        'The next line is not optional.  Edit the folder path on the next line as needed.'
        . FolderToWatch OpenOutlookFolder("Mailbox - TechnicLee\Inbox")
    End With
End Sub
  • Revision 4

I created this revision for Jimmy who asked for a version that would monitor the Inbox folder of every shared mailbox whose name begins with “FAX -“. The code searches through the message stores defined in the user’s Outlook profile and creates a folder monitor object for each store whose display name begins with “FAX -“. The folder monitor object will display a notification each time an item is added to the Inbox folder of the message store it’s associated with.

Part 1.

Follow these instructions to add this code to Outlook.

  1. Start Outlook
  2. Click Tools > Macro > Visual Basic Editor
  3. If not already expanded, expand Microsoft Office Outlook Objects
  4. If not already expanded, expand Modules
  5. Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
  6. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  7. Click the diskette icon on the toolbar to save the changes
  8. Close the VB Editor
Public Const SND_ASYNC = &H1

Public Declare Function sndPlaySound _
    Lib "winmm.dll" Alias "sndPlaySoundA" _ 
        (ByVal lpszSoundName As String, _
        ByVal uFlags As Long) _
    As Long 

Public Declare Function MessageBox _
    Lib "User32" Alias "MessageBoxA" _
        (ByVal hWnd As Long, _
        ByVal lpText As String, _
        ByVal lpCaption As String, _
        ByVal wType As Long) _
    As Long

Part 2.

Follow these instructions to add this code to Outlook.

  1. If not already expanded, expand Microsoft Office Outlook Objects
  2. Right-click on Class Modules, select Insert > Class Module
  3. In the Properties panel click on Name and enter clsFolderMonitor
  4. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  5. Edit the code as needed. I included comments wherever something needs to or can change
  6. Click the diskette icon on the toolbar to save the changes
Private WithEvents olkItems As Outlook.Items
Private strMessage As String
Private strSound As String
Private bolShowSender As Boolean
 
Private Sub Class_Initialize()
    'On the next three lines edit the default values as desired.'
    strMessage = "New message arrived."
    strSound = "C:\Windows\Media\Notify.wav"
    bolShowSender = False
End Sub
 
Private Sub Class_Terminate()
    Set olkItems = Nothing
End Sub
 
Private Sub olkItems_ItemAdd(ByVal Item As Object)
    Dim lngHandle As Long, lngReturn As Long
    sndPlaySound strSound, SND_ASYNC
    If bolShowSender Then
        MessageBox &O0, strMessage & vbCrLf & "Sender: " & Item.SenderName, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
    Else
        MessageBox &O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
    End If
End Sub
 
Public Sub FolderToWatch(objFolder As Outlook.Folder)
    Set olkItems = objFolder.Items
End Sub
 
Public Property Let Message(ByVal strValue As String)
    strMessage = strValue
End Property
 
Public Property Let ShowSender(ByVal bolValue As Boolean)
    bolShowSender = bolValue
End Property
 
Public Property Let Sound(ByVal strValue As String)
    strSound = strValue
End Property

Part 3.

Follow these instructions to add this code to Outlook.

  1. If not already expanded, expand Microsoft Office Outlook Objects
  2. Right-click on Class Modules, select Insert > Class Module
  3. In the Properties panel click on Name and enter clsJimmy
  4. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  5. Edit the code as needed. I included comments wherever something needs to or can change
  6. Click the diskette icon on the toolbar to save the changes
Private colMon As Collection

Private Sub Class_Initialize()
    Dim olkSto As Outlook.Store, objTmp As clsFolderMonitor
    Set colMon = New Collection
    For Each olkSto In Session.Stores
        If Left(olkSto.DisplayName, 5) = "FAX -" Then
            Set objTmp = New clsFolderMonitor
            With objTmp
                .FolderToWatch olkSto.GetDefaultFolder(olFolderInbox)
                .Message = "New message in mailbox " & olkSto.DisplayName
                .ShowSender = True
            End With
            colMon.Add objTmp, olkSto.DisplayName
        End If
    Next
    Set olkSto = Nothing
End Sub

Private Sub Class_Terminate()
    Dim intPtr As Integer, objTmp As clsFolderMonitor
    For intPtr = colMon.Count To 1 Step -1
        Set objTmp = colMon(intPtr)
        Set objTmp = Nothing
    Next
    Set objTmp = Nothing
    Set colMon = Nothing
End Sub

Part4.

Follow these instructions to add this code to Outlook.

  1. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  2. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  3. Click the diskette icon on the toolbar to save the changes
  4. Close the VB Editor
  5. Click Tools > Trust Center
  6. Click Macro Security
  7. Set Macro Security to “Warnings for all macros”
  8. Click OK
  9. Close Outlook
  10. Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.
Dim objFM1 As clsJimmy

Private Sub Application_Quit()
    Set objFM1 = Nothing
End Sub

Private Sub Application_Startup()
    Set objFM1 = New clsJimmy
End Sub

392 comments on “New Mail Notification for an Additional Mailbox

  1. First of all, thank you David sharing and supporting this.
    I have been using this code for my coworkers and I for the past year and works a treat! It has become something we depend on and a valuable tool.

    Since several of us have had our laptops replaced (some with Win10 and some with Win7) the common denominator seems to be that we all have outlook 2010. It used to be that we only received notifications for new email if outlook happened to be open at the time and since the switch to 2010, one gets flooded with notification for each email that came in overnight.

    Is there a way to only monitor and send notification if an email comes in while outlook is open and to ignore emails already in the folder when opening outlook?

    Thanks again, David.

    • Hi, Michael.

      You’re welcome. Glad the solution has been useful.

      What email solution are you using? Is it Exchange or something else?

    • We are using Exchange and it is a shared mailbox.
      As I booted up this morning, I had approx. 25 notifications I had to click through.
      It didn’t behave this way prior to Outlook 2010.

    • Hi David,
      I replied almost two months ago but it still says waiting for moderation.
      We are using Exchange and it is a shared mailbox.

      Thanks

    • Hi, Michael.

      The replies don’t appear until I approve them, which I don’t normally do until I’m ready to respond. Sorry to have taken so long to get back to you. I do this as I have time and energy and lately I haven’t had a lot of either.

      Which version of the code are you using, that in the original post or one of the revisions? If it’s the latter, which revision?

  2. Hi David,

    I cannot seem to get your script to work. I have followed your instructions and renamed the mailbox in part 3. However I am getting a run time error 91. It highlights this line in yellow objFM1.FolderToWatch OpenOutlookFolder(“Mailbox – Accommodation\Inbox”)

    Any ideas?

    • Hi, Jason.

      My first thought is that the path to the inbox folder may be incorrect. Add the code below to what you already have. Select the target folder, then run that macro. It will display the path to the selected folder. Use that path in the solution.

      Sub DisplayFolderPath()
          Const SCRIPT_NAME = "Display Folder Path"
          Dim olkFol As Outlook.MAPIFolder
          Set olkFol = Application.ActiveExplorer.CurrentFolder
          MsgBox "The path to the currently selected folder is " & vbCrLf & vbCrLf & olkFol.FolderPath, vbInformation + vbOKOnly, SCRIPT_NAME
          Set olkFol = Nothing
      End Sub
      
  3. Hey, a quick question if thats OK?

    I already have a script in ThisOutlookSession, so I have:-

    “ThisOutlookSession”
    “Module 1 – (your part 1)”
    “FolderMonitor (your part 2)”

    So does your part 3 go into a new module, or into the end of Module 1?…..or the end of my already populated “TheOutlookSession” – which I dont think will work.

    Still new to VB, so apologies 🙂

    thanks, Danny.

    • Hi, Danny.

      Is the code in ThisOutlookSession from one of my solutions? If so, which one? If not, then I’ll need to see that code to figure out how to integrate my code from this solution that must go into ThisOutlookSession with it.

    • Hey David,

      Thanks for your reply.

      No its one that I wrote, with help from google. Its a script that forwards an appointment when fired, to an email account, and then dismisses the appointment to make it look like a normal email. I am still very new to VB so I need to figure out how to incorporate your part 3 into this:-

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

      Private WithEvents olRemind As Outlook.Reminders
      Dim strSubject As String
      
      Private Sub Application_Reminder(ByVal Item As Object)
      Set olRemind = Outlook.Reminders
       
      'IPM.TaskItem to watch for Task Reminders.
      
      If Item.MessageClass  "IPM.Appointment" Then
        Exit Sub
      End If
       
      'Only fire this process if the appointment has a category "Send Message".
       
      If Item.Categories  "Send Message" Then
        Exit Sub
      End If
      
      'Setting the appointment values as the email values.
      
      strSubject = Item.Subject
      Dim objMsg As MailItem
      Set objMsg = Application.CreateItem(olMailItem)
       
        objMsg.To = Item.Location
        objMsg.SentOnBehalfOfName = "xxxx"
        objMsg.BCC = "xxxx"
        objMsg.Subject = Item.Subject
        objMsg.Body = Item.Body
        objMsg.Send
       
       
      Set objMsg = Nothing
      End Sub
      
      Private Sub olRemind_BeforeReminderShow(Cancel As Boolean)
       
      'Dismiss the appointment before it opens.
       
          For Each objRem In olRemind
                  If objRem.Caption = strSubject Then
                      If objRem.IsVisible Then
                          objRem.Dismiss
                          Cancel = True
                      End If
                      Exit For
                  End If
              Next objRem
       
      End Sub
      
    • Hi, Danny.

      You can just add my code to what you already have. Something like this

      Dim objFM1 As FolderMonitor
       
      Private Sub Application_Quit()
          Set objFM1 = Nothing
      End Sub
       
      Private Sub Application_Startup()
          Set objFM1 = New FolderMonitor
          'Edit the folder path on the next line as needed.'
          objFM1.FolderToWatch OpenOutlookFolder("Mailbox - TechnicLee\Inbox") 
      End Sub 
      
      Private WithEvents olRemind As Outlook.Reminders
      Dim strSubject As String
       
      Private Sub Application_Reminder(ByVal Item As Object)
      Set olRemind = Outlook.Reminders
        
      'IPM.TaskItem to watch for Task Reminders.
       
      If Item.MessageClass  "IPM.Appointment" Then
        Exit Sub
      End If
        
      'Only fire this process if the appointment has a category "Send Message".
        
      If Item.Categories  "Send Message" Then
        Exit Sub
      End If
       
      'Setting the appointment values as the email values.
       
      strSubject = Item.Subject
      Dim objMsg As MailItem
      Set objMsg = Application.CreateItem(olMailItem)
        
        objMsg.To = Item.Location
        objMsg.SentOnBehalfOfName = "xxxx"
        objMsg.BCC = "xxxx"
        objMsg.Subject = Item.Subject
        objMsg.Body = Item.Body
        objMsg.Send
        
        
      Set objMsg = Nothing
      End Sub
       
      Private Sub olRemind_BeforeReminderShow(Cancel As Boolean)
        
      'Dismiss the appointment before it opens.
        
          For Each objRem In olRemind
                  If objRem.Caption = strSubject Then
                      If objRem.IsVisible Then
                          objRem.Dismiss
                          Cancel = True
                      End If
                      Exit For
                  End If
              Next objRem
        
      End Sub
      
    • Hey,

      Sorry for the delay and thanks for your comment.

      Its not working unfortunately 😦 Think it needs a slight shuffle,

      Thanks,

      Danny.

  4. Hi David,

    At first, thank you so much for the vba codes.

    I’m using the revision 1 and it works great. However there is a small problem here: the vba will stop working whenever I receive an email from Microsoft Exchange about Undeliverable email or Delivery Delayed. Please kindy advise how to fix it. All I had to do is restart the Outlook 😦

    • Hi, Vietpl.

      You’re welcome!

      In part 2 of the code change the olkItems_ItemAdd subroutine to the version below. That should fix the issue.

      Private Sub olkItems_ItemAdd(ByVal Item As Object)
          Dim lngHandle As Long, lngReturn As Long
          If Item.Class = olMail Then
              sndPlaySound strSound, SND_ASYNC
              If bolShowSender Then
                  MessageBox &O0, strMessage & vbCrLf & "Sender: " & Item.SenderName, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
              Else
                  MessageBox &O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
              End If
          End If
      End Sub
      
    • Hi David,

      I will try that and update you on the outcome.
      By the way, I’m trying to figure it out by using the codes below (edited from yours) to prevent the new in coming emails with specified subjects which contain specified keywords: “Undeliverable:”, “Delivery delayed:”, Backup on”, “Automatic reply”, “Out of office:” but seem not working, can you please help to check what is wrong for me? Sorry for my bad English.

      Private Sub olkItems_ItemAdd(ByVal Item As Object)
      Dim lngHandle As Long, lngReturn As Long, bolUnd As Boolean, bolOOO, bolOOd, bolOOe, bolOOf As Boolean
      bolUnd = InStr(1, Item.Subject, “Undeliverable:”)
      bolOOO = InStr(1, Item.Subject, “Delivery delayed:”)
      bolOOd = InStr(1, Item.Subject, “Backup on”)
      bolOOe = InStr(1, Item.Subject, “Automatic reply”)
      bolOOf = InStr(1, Item.Subject, “Out of office:”)
      If (Not bolUnd) And (Not bolOOO) And (Not bolOOd) And (Not bolOOe) And (Not bolOOf) Then
      sndPlaySound SOUND_TO_PLAY, SND_ASYNC
      If bolShowSender Then
      MessageBox &O0, strMessage & vbCrLf & “Sender: ” & Item.SenderName, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
      Else
      MessageBox &O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
      End If
      End If
      End Sub

    • Hi David,

      I will try it and let you know the outcome. By the way I’m trying to edit the part 2 as below to prevent notification popup for new email with specified subjects which contains one of these keywords: Undeliverable, Delivery delayed, Backup on, Automatic reply, Out of office. But it seems not working. Can you please help to check what is wrong? Thank you very much.

      Private Sub olkItems_ItemAdd(ByVal Item As Object)
      Dim lngHandle As Long, lngReturn As Long, bolUnd As Boolean, bolOOO, bolOOd, bolOOe, bolOOf As Boolean
      bolUnd = InStr(1, Item.Subject, “Undeliverable:”)
      bolOOO = InStr(1, Item.Subject, “Delivery delayed:”)
      bolOOd = InStr(1, Item.Subject, “Backup on”)
      bolOOe = InStr(1, Item.Subject, “[Daiichi]”)
      bolOOf = InStr(1, Item.Subject, “[REC]-SLA OVERDUE”)
      If (Not bolUnd) And (Not bolOOO) And (Not bolOOd) And (Not bolOOe) And (Not bolOOf) Then
      sndPlaySound SOUND_TO_PLAY, SND_ASYNC
      If bolShowSender Then
      MessageBox &O0, strMessage & vbCrLf & “Sender: ” & Item.SenderName, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
      Else
      MessageBox &O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
      End If
      End If
      End Sub

    • Hi David,

      Thank you very much! It works very well.

      Here I have another concern, I want to prevent the notification of Undeliverable, Delivery delayed emails from Microsoft Outlook (You helped me out this problem), and also want to prevent notification for new emails which the subject contains specified keywords likes “Backup on”, “Automatic reply”, “Out of office”. Can you please help me to make it happens?

      Below is my codes but seems it doesn’t work 😦

      Private Sub olkItems_ItemAdd(ByVal Item As Object)
         Dim lngHandle As Long, lngReturn As Long, bolUnd As Boolean, bolOOO, bolOOd, bolOOe, bolOOf As Boolean
          bolUnd = InStr(1, Item.Subject, "Undeliverable:")
         bolOOO = InStr(1, Item.Subject, "Delivery delayed:")
          bolOOd = InStr(1, Item.Subject, "[Backup on]")
          bolOOe = InStr(1, Item.Subject, "Out of office]")
          bolOOf = InStr(1, Item.Subject, "Automatic reply")
          If (Not bolUnd) And (Not bolOOO) And (Not bolOOd) And (Not bolOOe) And (Not bolOOf) Then
              sndPlaySound SOUND_TO_PLAY, SND_ASYNC
              If bolShowSender Then
                  MessageBox &amp;O0, strMessage &amp; vbCrLf &amp; "Sender: " &amp; Item.SenderName, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
              Else
                  MessageBox &amp;O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
              End If
          End If
        End Sub
      
    • Hi, Allan.

      You’re welcome.

      On line #2 declare all the variables that begin with bol to be of type Boolean just as bolUnd and bolOOf are.

    • Hi, Allan.

      Change line #2 from

         Dim lngHandle As Long, lngReturn As Long, bolUnd As Boolean, bolOOO, bolOOd, bolOOe, bolOOf As Boolean
      

      to

         Dim lngHandle As Long, lngReturn As Long, bolUnd As Boolean, bolOOO As Boolean, bolOOd As Boolean, bolOOe As Boolean, bolOOf As Boolean
      
    • Hi David,

      It’s working perfect now. Thank you 🙂
      I have another question, is there any way to mark those new emails with specified subjects as read by VBA?

    • Hi, Allan.

      Try this version.

      Private Sub olkItems_ItemAdd(ByVal Item As Object)
          Dim lngHandle As Long, lngReturn As Long, bolUnd As Boolean, bolOOO As Boolean, bolOOd As Boolean, bolOOe As Boolean, bolOOf As Boolean
          bolUnd = InStr(1, Item.Subject, "Undeliverable:")
          bolOOO = InStr(1, Item.Subject, "Delivery delayed:")
          bolOOd = InStr(1, Item.Subject, "[Backup on]")
          bolOOe = InStr(1, Item.Subject, "Out of office]")
          bolOOf = InStr(1, Item.Subject, "Automatic reply")
          If (Not bolUnd) And (Not bolOOO) And (Not bolOOd) And (Not bolOOe) And (Not bolOOf) Then
              sndPlaySound SOUND_TO_PLAY, SND_ASYNC
              Item.UnRead = False
              Item.Save
              If bolShowSender Then
                  MessageBox &amp;O0, strMessage &amp; vbCrLf &amp; "Sender: " &amp; Item.SenderName, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
              Else
                  MessageBox &amp;O0, strMessage, olkItems.Parent.Name, vbInformation + vbOKOnly + vbSystemModal
              End If
          End If
        End Sub
      
  5. Hi
    Im searching for the Path. How can i find out the correct path to my
    objFM1.FolderToWatch OpenOutlookFolder(“path i need to find”)
    Is that path stored anyware in the Outlook?
    Thanks a lot
    Novski

    • Hi, Novski.

      Add this code to that you already have. Once you’ve done that, select a folder and run this macro. It will display the path to the selected folder.

      Sub DisplayFolderPath()
          Const SCRIPT_NAME = "Display Folder Path"
          Dim olkFol As Outlook.MAPIFolder
          Set olkFol = Application.ActiveExplorer.CurrentFolder
          MsgBox "The path to the currently selected folder is " & vbCrLf & vbCrLf & olkFol.FolderPath, vbInformation + vbOKOnly, SCRIPT_NAME
          Set olkFol = Nothing
      End Sub
      
  6. Hi

    I am facing issue here , getting error and VB is highlighting “Private WithEvents……”

    Compile error:

    Only Valid in object module

    Please help,

    • Hi, Santosh.

      Based on the error it sounds like you put the code for part #2 in a regular module rather than in a class module. Please double-check the instructions for part #2.

  7. Hi
    I have problems with the revision 1 on part 2 point 3:
    “In the Properties panel click on Name and enter FolderMonitor”
    I can’t follow…
    Maybe my Outlook 2013 is different?
    The error i get is this:
    On German: Fehler beim Kompilieren: Benutzerdefinierter Typ anstelle eines Projekts erwartet.
    Google translate: Compile Error: User-defined type rather than a project expected.

    • Hi David, Thanks for the reply. I can not folow that part.
      What i did is to Rename the Projectname to FolderMonitor. I can’t find a propterties panel or a field named “Name” to enter FolderMonitor…
      Is Outlook 2013 different?
      Thanks a lot.

    • Hi, Novski.

      In the VB editor, select the class module then press F4 to open the Properties panel. Click i the Name field and change the name.

  8. Hi David,

    Thanks so much for this!

    I’ve been testing the different revisions trying to understand the code (as I’m not a VBA coder).

    My question relates to Revision 4:

    I’ve tried to implement a version of this script, changing the code

    If Left(olkSto.DisplayName, 5) = “FAX -” Then

    To match the folder structure of my shared mailboxes – however when I attempt to execute the code whenever I get a match (confirmed via a msgbox) the system generates a

    “run-time error ‘438’:

    Object doesn’t support this property or method”

    When I debug the error it takes me to:

    Private Sub Application_Startup()
    Set objFM1 = New clsJimmy
    End Sub

    Any help would be greatly appreciated. Sorry if this has come up before but I was unable to find it in the previous comments….

    Thanks,
    Chris

    • Hi, Chris.

      Based on your explanation, my best guess is that the folder path being passed is invalid. You mention that you edited the line

      If Left(olkSto.DisplayName, 5) = "FAX -" Then
      

      How did you change it? Also, please tell me more about the shared folders. Are they public folders or folders in another mailbox?

    • Hi David,

      The code change is attached:

      For Each olkSto In Session.Stores
      MsgBox (Left(olkSto.DisplayName, 11))
      If Left(olkSto.DisplayName, 11) = “App Support” Then
      MsgBox (“enter If statement”)

      I used the messages to debug the code and can confirm that we enter the ‘IF’ statement – followed by the error described previously.

      In terms of the folders I’d like to monitor it’s the inboxes of multiple shared mailboxes (which all start with the “App Support” naming convention).

      Thanks,
      Chris

    • Hi David,

      Just discovered the VBA ‘Debugger’ mode and identified that the last statement that executes prior to the error is (in the clsFolderMonitor Class):

      Private Sub Class_Terminate()
      Set olkItems = Nothing
      End Sub

      Thanks,
      Chris

    • Chris,

      The code in the Class_Terminate sub cannot possible cause the error. We need to dig a little deeper. Since you’ve discovered the debugger here’s what I’d like you to do.

      1. Set a breakpoint on this line: If Left(olkSto.DisplayName, 11) = “App Support” Then. To to that, place the insertion point on that line and press F9. The line should turn red.
      2. Send yourself a test message. When the code gets to the breakpoint it will pause and display the debugger. You can then execute the code one line at a time by pressing F8. Each time you press F8 the debugger will execute the current line and move to the next line. Do this slowly enough to note which line generates the error.
    • Hi David,

      I’ve followed your instructions and the code that seems to be causing the error is

      With objTmp
      .FolderToWatch olkSto.GetDefaultFolder(olFolderInbox)

      Also prior to the error if I hover my mouse pointer over olFolderInbox from the above statement it shows “olFolderInbox = 6”

      This is the last code to execute prior to the Class_Terminate sub (as described earlier)

      Thanks,
      Chris

    • Hi, Chris.

      Yes, that would be the issue. I don’t know if I still have Office 2007 installed anywhere. I’ll check and see. If I do, then I’ll see about creating a version of this that works with it.

    • Hi David,

      Just to let you know I think I may have stumbled onto a solution (of sorts)…

      After identifying that the code that was causing the error was:

      .FolderToWatch olkSto.GetDefaultFolder(olFolderInbox)

      I reverted to using the OpenOutlookFolder function (from previous revisions)

      .FolderToWatch OpenOutlookFolder(olkSto.DisplayName & “\Inbox”)

      replaced

      .FolderToWatch olkSto.GetDefaultFolder(olFolderInbox)

      and it seems to be working now – I’ll complete some more vigorous testing and let you know if there are any issues.

      Thanks again,
      Chris

    • Hi David
      I have another question. How can i find out the correct path to my

      objFM1.FolderToWatch OpenOutlookFolder(“path i need to find”)

      I can’t find out where il find that…
      Thanks a lot
      Novski

  9. VB Sound Alert help for two shared mail box this is for only one Shared mail box help I want for all the two not for my personal mail is anyone can help me out

    • Hi, Selvaraj Nadar.

      You can monitor as many mailboxes as you want. To monitor additional mailboxes modify the code in part 3 to something like this

      Dim objFM1 As FolderMonitor
      Dim objFM2 As FolderMonitor
       
      Private Sub Application_Quit()
          Set objFM1 = Nothing
          Set objFM2 = Nothing
      End Sub
       
      Private Sub Application_Startup()
          Set objFM1 = New FolderMonitor
          'Edit the folder path on the next line as needed.'
          objFM1.FolderToWatch OpenOutlookFolder("Mailbox - Somemailbox\Inbox") 
          Set objFM2 = New FolderMonitor
          'Edit the folder path on the next line as needed.'
          objFM2.FolderToWatch OpenOutlookFolder("Mailbox - Anothermailbox\Inbox") 
      End Sub 
      
  10. Hello David,

    I’m french, so not sure on my english.

    I found your post while I wanted to have an alert when a new mail arrived in the inbox from other mailboxes.
    I used office 2007, with exchange 2007.
    I lunch outlook with my profil, and I had added 10 mailboxes with tools>account parameter>modifiy>more parameter>avanced.
    We use personnal email like : john.doe@my.domain.fr
    and project email : thebigtower@my.domain.fr
    And everybody have access to project email.

    So I wanna have an alert when on each project email, a new mail incomme in the inbox.

    • Salut, likum.

      Modifier la ligne 10 du code dans la Partie 3. Sur cette ligne, modifier le chemin “Mailbox – TechnicLee\Inbox” sur le chemin de la boîte de réception de la boîte aux lettres Projets. Si vous ne savez pas quel est le chemin, puis ajouter ce code pour que vous avez déjà. Une fois que vous avez fait cela, sélectionnez la boîte de réception de la boîte aux lettres Projets et exécutez la macro “GetFolderPath”. Il affichera le chemin vers ce dossier. Copiez et collez ce chemin dans la ligne 10 de la macro de notification.

      Sub GetFolderPath()
          Dim olkFol As Outlook.MAPIFolder
          Set olkFol = Application.ActiveExplorer.CurrentFolder
          MsgBox "Le chemin vers le dossier sélectionné est curectly" & vbCrLf & vbCrLf & olkFol.FolderPath, vbInformation + vbOKOnly, "Obtenez Chemin Dossier"
          Set olkFol = Nothing
      End Sub
      
    • Hello David,

      Thank’s :). It’s work.
      For me it’s :
      objFM1.FolderToWatch OpenOutlookFolder(“\\Boîte aux lettres – my_mailbox_name\Boîte de réception”) because I’m in french.

      I have juste one more question :
      How can I prompt the mailbox name, which recieve the email, in the MessageBox ?

    • Hello twice,

      I found it.
      I juste change in part2 :
      MessageBox &O0, “De : ” & Item.SenderName & vbCrLf & “A : ” & Item.To, “Nouveau mail”, vbInformation + vbOKOnly + vbSystemModal

      Thank’s for all.

  11. When I open outlook I get this message error. (defined type not defined) and box opens with code.
    Dim objFM1 As FolderMonitor

    Private Sub Application_Quit()
    Set objFM1 = Nothing
    End Sub

    Private Sub Application_Startup()
    Set objFM1 = New FolderMonitor
    ‘Edit the folder path on the next line as needed.’
    objFM1.FolderToWatch OpenOutlookFolder(“Mailbox – TechnicLee\Inbox”)
    End Sub

    And I changed TechnicLee to match the mailbox I need.

  12. Hi Josh,

    Excellent script. I have been using this for a while.
    I have another piece of code that I would like to incorporate so that rather than creating a message box, a different email is sent to my main inbox. This would stop the need to click “okay” on the pop-up and I can automatically delete the alert messages nightly.

    I have

    > Sub SendNew(Item As Outlook.MailItem)
    >
    > Dim objMsg As MailItem
    >Set objMsg = Application.CreateItemFromTemplate(“C:\Alert.oft”)
    >
    >objMsg.Recipients.Add “Me@foo.com”
    >
    >objMsg.Send
    >
    >End Sub

    Which runs fine as a script in Outlook rules and alerts, but I am unsure of how to incorporate it into your code which monitors another mailbox.

    • Never mind, silly me. I just got this working. I added

      >Dim objMsg As Outlook.MailItem
      >Set objMsg = Application.CreateItemFromTemplate(“C:\Alert.oft”)
      >
      >objMsg.Recipients.Add “Me@foo.com”
      >
      >objMsg.Send

      To the olkItems_ItemAdd private sub and commented out the MessageBox and sndPlaySound lines.

      Thanks,
      B

Leave a comment