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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scanning emails in outlook 1

Status
Not open for further replies.

dpdg

Programmer
May 23, 2005
148
US
Is there a way to scan emails that come in through Outlook?

We have a program that submits invoices to our customer and when there is an error, their program sends an automated email back to us stating the error. We then need to flag the row in the database with the error code depending on what the error is.

My client wants to know if there is a way to scan the emails with the error information for certain phrases when they come in.

Thanks.
 
Here is some code I have been using for moving certain emails to another folder. It will probably get you started with what you need.

Code:
Public Sub ScanEmail()
      
    Dim appOutlook        As Outlook.Application
    Dim ns                As Outlook.NameSpace
    Dim Inbox             As MAPIFolder
    Dim MoveToFolder      As MAPIFolder
    Dim i                 As Integer
    Dim strSubject        As String
    Dim strSender         As String
    
    DoCmd.SetWarnings False
    Set appOutlook = CreateObject("Outlook.Application")
    Set ns = appOutlook.GetNamespace("MAPI")
    Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    
    strSender = "Test User"
    strSubject = "Test Subject"
      
    ' Move from end to start since moving items to new folder changes collection
    For i = Inbox.Items.Count To 1 Step -1
      If Inbox.Items(i).UnRead = True And Inbox.Items(i).SenderName = strSender And Inbox.Items(i).Subject = strSubject Then
        Set MoveToFolder = Inbox.Folders("SQL Logs")
        Inbox.Items(i).UnRead = False
        Inbox.Items(i).Move MoveToFolder
      End If
    Next

    Set appOutlook = Nothing
    Set ns = Nothing
    Set Inbox = Nothing

End Sub
 
Thanks. This code was very helpful. I finished the part of the project I was working on with the help of this code. It works fine!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top