Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monitor Outlook email via Access 1

Status
Not open for further replies.

nguenthe

MIS
Jul 2, 2004
16
0
0
US
I receive emails every half hour to indicate that one of our servers is running. When the server goes down, it often goes unnoticed for hours and then we realize that we did not get the emails. I would like to write a module in access using vba so I can monitor the emails that get routed to a personal folder/pst via Outlook rule.

In access, I would monitor the subfolder folder in the PST file and if there were no mail items that had been sent there in more than 30 minutes it would kick off a bunch of other emails. I spent some time reading how to do this, but I am stuck trying to loop through all of the attachments in the pst subfolder. Can anyone assist with this part?

Thanks in advance.
 

Someone probably can, but you have to show us what code you have and where you are having the problem.
 
I think I mostly have it. The only thing that I am not super comfortable with is the Folder ID of the Folder in the PST:

Code:
Sub monitor_Email()

Dim myNS As NameSpace
 Set myNS = Outlook.Application.GetNamespace("MAPI")

Dim oItem As Outlook.MailItem
Dim dMaxDateTime As Date

Dim inFolder As Outlook.MAPIFolder
 Set inFolder = myNS.GetFolderFromID("00000000124CAEF748418742B05D015F9641638F22800000")
 
 For Each oItem In inFolder.Items
     If oItem.ReceivedTime > dMaxDateTime Then
        dMaxDateTime = oItem.ReceivedTime
     End If
     
 Next
    
    If VBA.DateDiff("n", Now(), dMaxDateTime) < -30 Then
        'rattle off spam to IT about the EDI server
    End If

End Sub
 

I can understand your trepidation. Outlook is a strange beast and the GetFolderFromID is daunting, but there is another method to get there involving the use of the Explorer Pane which has your Mail Folders, Calendar Folders and Contact Folders in it.

You have to set varibles to reference the Explorer, Navigation Pane, Navigation Folder, Navigation Group (maybe) and MailModule. In the Mail Module will be your Mail Folders and you can reference them by name from there. I have not done that for Mail folders, but I have for Contact folders... it should work similarly.

The help for Outlook is also very different than other Office Applications, but some research should get you the information you want... if not, I may have some time later to help with the syntax.
 
I finally made a couple minutes to go back through this when the folder ID changed and the program started sending out invalid emails. It is not that bad to loop through the folders. Here is what I ended up with:

Code:
Sub monitor_Incoming_Email()

Dim myNS As NameSpace
 Set myNS = Outlook.Application.GetNamespace("MAPI")

Dim oItem As Outlook.MailItem
Dim dMaxDateTime As Date

Dim oAllFolders As Outlook.Folders
Dim oFolder As Outlook.Folder

Set oAllFolders = myNS.Folders
   For Each oFolder In oAllFolders
       If oFolder.Name = "2010" Then
                For Each oItem In oFolder.Items
                    If oItem.ReceivedTime > dMaxDateTime Then
                       dMaxDateTime = oItem.ReceivedTime
                    End If
                Next
 
            If VBA.DateDiff("n", Now(), dMaxDateTime) < -30 Then
                'rattle off spam to IT about the EDI server
                'my call to our email routine
            End If
       End If
   Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top