Results 1 to 4 of 4

Thread: Tough Outlook Question?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    2
    Any clue if it is possible, and if so how to check for a message in your inbox for a particular subject and then write the message to a text file somewhere on your hard drive?

    Please only replies from people that have an idea how to do it. No "check the object browser" type responses.

    Thanks.

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    this uses the Outlook 8.0 object libriary:


    Code:
    Sub ReadEmail()
    Dim oApp As Outlook.Application
    Dim oNameSpace As Outlook.NameSpace
    Dim oFolder As Outlook.MAPIFolder
    Dim oMailItem As Object
    Dim sMessage As String
    Set oApp = New Outlook.Application
    Set oNameSpace = oApp.GetNamespace("MAPI")
    Dim Filename As String
    Dim fnum As Byte
    oNameSpace.Logon "MyProfile", , False, True
    
    Set oFolder = oNameSpace.GetDefaultFolder(olFolderInbox)
    
    For Each oMailItem In oFolder.Items
      With oMailItem
        
        If oMailItem.UnRead = True Then
         If UCase(oMailItem.Subject) = "WHATEVER" Then
        
           Debug.Print oMailItem.Body
           
           'create a unique file name
           Filename = "C:\MailText" & Format(Now, "yymmddhhnnss") & ".txt"
           fnum = FreeFile
           Open Filename For Binary As fnum
           Put #fnum, , oMailItem.Body
           Close fnum
         
          
          End If
        End If
      End With
    Next oMailItem
    Set oMailItem = Nothing
    Set oFolder = Nothing
    Set oNameSpace = Nothing
    Set oApp = Nothing
    End Sub
    Mark
    -------------------

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    2

    Thanks

    You are quite awesome, that worked great!

    Thanks!!!!!!!!

  4. #4
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153

    Permission denied

    Hi. I copied the exact code and tried running the program. I get an error message "permission denied". I'm under the impression that I have administrative rights. Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width