Results 1 to 4 of 4

Thread: extract data from open outlook email

  1. #1

    Thread Starter
    Fanatic Member kevin_sauerwald's Avatar
    Join Date
    Feb 2002
    Location
    outside Philly
    Posts
    516

    extract data from open outlook email

    so I have seen lots of code to make an instance outlook and then run through it.. etc..

    I want to have an app that runs when I want to.. to extract data from an open
    email that I have open..

    so so I have an email open in outlook that I want to extract some data from
    and I right click make it call my app and it then gets the top outlook email
    and then does what it needs to..

    anyone got an example of how to do that ?

    thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: extract data from open outlook email

    anyone got an example of how to do that ?
    not enough information
    so I have seen lots of code to make an instance outlook and then run through it
    what have you got so far, for your task?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Fanatic Member kevin_sauerwald's Avatar
    Join Date
    Feb 2002
    Location
    outside Philly
    Posts
    516

    Re: extract data from open outlook email

    here is code I have already seen

    Code:
    Sub Main()
            ' Create Outlook application.
            Dim oApp As Outlook.Application = New Outlook.Application
     
            ' String used for comparison with mail item.
            Dim sClassComp = "IPM.Note"
     
            ' Get Mapi NameSpace.
            Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
     
            ' Get Messages collection of Inbox.
            Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
            Dim oItems As Outlook.Items = oInbox.Items
            Console.WriteLine("Total : " & oItems.Count)
     
            ' Get unread e-mail messages.
            oItems = oItems.Restrict("[Unread] = true")
            Console.WriteLine("Total Unread : " & oItems.Count)
     
            ' Loop each unread message.
            Dim oMsg As Outlook.MailItem
            Dim i As Integer
            For i = 1 To oItems.Count
                'Test to make sure item is a mail item
                'and not a meeting request.
                If oItems.Item(i).MessageClass = sClassComp Then
                    oMsg = oItems.Item(i)
     
                    Console.WriteLine(i)
                    Console.WriteLine(oMsg.SenderName)
                    Console.WriteLine(oMsg.Subject)
                    Console.WriteLine(oMsg.ReceivedTime)
                    Console.WriteLine(oMsg.Body)
                    Console.WriteLine("---------------------------")
                End If
            Next
     
            ' Clean up.
            oApp = Nothing
            oNS = Nothing
            oItems = Nothing
            oMsg = Nothing
     
        End Sub
    what my code right now does is check what you are doing every 5 seconds.. by just checking the
    topmost window.. so what I want to make it do now is.. if it see's its outlook.. I want it to check
    the email address's it came from .. really I just want the domain name.. so I can then group
    how often I'm sending emails to certain clients..

    this is what it does so far..

    Code:
           Dim hWnd As IntPtr = GetForegroundWindow()
            If hWnd = IntPtr.Zero Then Exit Sub
            Dim pid As Integer = 0
            If 0 = GetWindowThreadProcessId(hWnd, pid) Then Exit Sub
            Dim proc As Process = Process.GetProcessById(pid)
            If proc Is Nothing Then Exit Sub
            Label1.Text = proc.ProcessName
            Label1.Text = proc.MainWindowTitle
            If gLastName <> proc.MainWindowTitle Then
    
                If proc.MainModule.FileVersionInfo.InternalName = "devenv.exe" Or proc.MainModule.FileVersionInfo.InternalName = "vshost.exe" Then
                    Exit Sub
                End If
                'Post the last entry since you are on a new one now
                TotalTime = gTimein - Now
                MyWindowData.Time = TotalTime.ToString
                PostEntry()
    
                'Now get the new Window Data
    
    
                gLastName = proc.MainWindowTitle
                gTimein = Now
                MyWindowData.App = proc.MainModule.FileVersionInfo.InternalName
                MyWindowData.FormTitle = proc.MainWindowTitle
    
    
            End If
        End Sub
    just kinda checks whats going on.. gets the name and subname.. marks a time.. but like I said
    when it comes back as OUTLOOK.. I want to make it then find the address's that are in the
    email..

    there a way to do this ?

    thanks..

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: extract data from open outlook email

    in what application or language are you working in?
    the above samples look like vb.net, is that what you are using?

    to automate an existing open instance of outlook, try
    Code:
    oapp = getobject("outlook.application")
    if you are working in vba or similar you may need the SET keyword
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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