Monitor another users Mailbox for new mail

  • Thread starter sandy.donaldson
  • Start date
S

sandy.donaldson

Hi All,

Just getting started with Outlook and VBA and am wondering if this is
possible.

I can write a macro that will monitor my Mailbox for incoming mails,
but I would like to monitor another mailbox and have it alert me when a
new message arives.

e.g. We have an IT malbox that myself and someone else monitors. If we
are not at our desk when a new message arrives, we are not alerted. I
would like a message box to permanently be displayed when a new mail
message arrives in the IT mailbox.

Hope someone can point me in the right direction

Thanks in advance,

Sandy
 
K

Ken Slovak - [MVP - Outlook]

If the mailbox is opened as part of your profile you can get the folder you
want, access it's Items collection and handle ItemAdd just as you would with
an Items collection in your own mailbox.
 
S

sandy.donaldson

Hi Ken,

Can you give me quick example of the code to do this.

Failing that, can you point me to some info on the web about this.

Thanks in advance,

Sandy
 
K

Ken Slovak - [MVP - Outlook]

The ItemAdd event handler would have to be placed in a class module or the
default ThisOutlookSession class module (or in a VBA UserForm). This assumes
use in ThisOutlookSession:

Private WithEvents colItems As Outlook.Items

Private Sub Application_Startup()
Dim oTop As Outlook.MAPIFolder
Dim oFolder As Outlook.MAPIFolder
Dim oNS As Outlook.NameSpace

Set oNS = Application.GetNameSpace("MAPI")

'change the mailbox name to whatever it is.
Set oTop = oNS.Folders.Item("Mailbox - IT")
Set oFolder = oTop.Folders.Item("Inbox")

Set colItems = oFolder.Items
End Sub

Private Sub colItems_ItemAdd(ByVal Item As Object)
'whatever
End Sub
 
S

sandy.donaldson

Thanks a lot Ken, all works fine now.

Cheers

The ItemAdd event handler would have to be placed in a class module or the
default ThisOutlookSession class module (or in a VBA UserForm). This assumes
use in ThisOutlookSession:

Private WithEvents colItems As Outlook.Items

Private Sub Application_Startup()
Dim oTop As Outlook.MAPIFolder
Dim oFolder As Outlook.MAPIFolder
Dim oNS As Outlook.NameSpace

Set oNS = Application.GetNameSpace("MAPI")

'change the mailbox name to whatever it is.
Set oTop = oNS.Folders.Item("Mailbox - IT")
Set oFolder = oTop.Folders.Item("Inbox")

Set colItems = oFolder.Items
End Sub

Private Sub colItems_ItemAdd(ByVal Item As Object)
'whatever
End Sub
 

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